RichText Formatting Issue in Search Results Table

Hi, guys!!

I followed Nayeli’s video of creating a Search for a database and it worked like a charm! The only hiccup I had was that in my search results table, the results are showing the RichText code as well as the text, instead of just the text. (see screenshot) I may just be missing something simple, but obviously, I would like just the text to appear. Do I need two identical columns in my database with identical information - one with RichText formatting for the Dynamic Page and one unformatted for tables (please say no, please say no . . . ).

Also, this particular search is always going to return just one record. Is it possible to send the results straight to the dynamic page or to regular text fields right there on the search page instead of to a results table so I could make it look pretty?

Thank you so much to everyone on the Wix Code team for being so patient with us newbie coders and to the other beta team members for sharing our work!! Thank you, thank you, thank you!!

1 Like

Hey there,

I would guess that your text is showing up with the tags because the field in the table is set to the wrong type. Try deleting the field you have and creating another one with the same name and label, but make sure the type is rich text.

Yes, you can send the results to non-table elements if you will only have one result. You need to change the code a bit. Here is the general concept:

wixData.query("CollectionName")
  .contains("fieldKey", "value")
  .find()
  .then( res => {
    //this is where you make the changes
    $w("#text1").text = res.items[0].title;
    $w("#text2").html = res.items[0].rich;
    //...
  } );

Basically, for each field you want to show in an element you need to add a line that:

  • Selects the element - e.g. $w(“#myElement”)

  • Sets the text, value or html property - e.g. .text = (you probably want to use .html for rich text fields)

  • Sets it with the value from the query results - e.g. res.items[0].fieldKey where res is the results object, items[0] is the first item of the results (also the only item in your collection), and fieldKey is the field key from your collection.

1 Like

Ok. Let me go try all of that . . . Thank you!

Ok. I got the Rich Text issue fixed. I misunderstood you at first and thought I had to delete the field from the database, but in actuality, I just had to delete and re-add that field’s COLUMN in the table and make sure when I added the new one that Rich Text was selected. Because, although you can edit a column’s name and fieldname, you can’t edit its field type. You can only delete and re-add (and set it correctly this time! Lol).

Now I am off to try the new piece of code to send the information to a regular text field instead of a table. Fingers crossed.

Oops, sorry that I wasn’t clear enough, but glad to hear you got it working.

Good luck with the code.

1 Like

I did it!!! I did it!!! It works!!! Thank you so much!!! And I actually understood what you told me to do!!!

I now can send my results either to a table or to a customized text layout!!! Thank you!!!

1 Like

That’s awesome you got it working!
Have fun coding and don’t forget to show off your work :smiling_face:

1 Like

how to make the result in box like this?