This is a migrated thread and some comments may be shown as answers.

Notes Field in Template

3 Answers 14 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 23 Jun 2015, 03:43 PM

So I'm trying to move some of my data binding to templates to allow conditional formatting, but I've noticed something when binding a notes field directly to a <p> tag vs. rendering it in the Template. The binding adds <br> tags in place of the carriage returns so the notes format correctly; the template does not.

 Here's the template:

         # if(PeopleNotes != null && PeopleNotes != '' ) { # <div class='inputWrapper' id='main_notes'>
        <label for='main_notesInput'>Notes</label>
        <p id='NoteField'>#:  PeopleNotes #</p>
        </div> # } #

 

Which doesn't include the <br> tag, vs:

                <div class="inputWrapper" id="main_notes">
                    <label for="main_notesInput">Notes</label>
                    <p id="NoteField" data-bind="text: selectedPerson.PeopleNotes"></p>
                </div>

 which does. Suggestions?

3 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 25 Jun 2015, 08:05 AM
Hi,

the text binder passes through jQuery .text method, which automatically converts new lines to <BR> elements.

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bryan
Top achievements
Rank 1
answered on 25 Jun 2015, 01:45 PM

OK. How would I get that formatting in the template? I can't use the string replace 

.replace(/(?:\r\n|\r|\n)/g, '<br />')

to return the same result, since it results in an invalid template. Can I pass it through the JQuery text method in the template? Doesn't seem to work for me.

0
Petyo
Telerik team
answered on 26 Jun 2015, 11:06 AM
Hi,

the approach you have taken seems correct and works here.
Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Templates
Asked by
Bryan
Top achievements
Rank 1
Answers by
Petyo
Telerik team
Bryan
Top achievements
Rank 1
Share this question
or