Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockout set initial value of an input field where html is allowed
    primarykey
    data
    text
    <p>I have two input fields first name and last name. Application was running really well. Suddenly someone came in from Mars and input something like this in those input fields</p> <p><code>*(~'@@~&gt;?&lt;+!""*%$)!</code></p> <p>for both first name and last name. Now don't ask me why he did this cause in Mars this is very common. You can try it on this fiddle</p> <p><a href="http://jsfiddle.net/farrukhsubhani/3RjRF/" rel="nofollow">http://jsfiddle.net/farrukhsubhani/3RjRF/</a></p> <p>This text then went into my database and now when i retrieve it it came back like this</p> <p><code>*(~&amp;#39;@@~&amp;gt;?&amp;lt;+!&amp;quot;&amp;quot;*%$)</code> which is ok for me as its html and I can place it back into knockout and it gets populated as html as you can see in fiddle above. However this Mars guy then thought that on Earth this is not a nice name to be with so he tried to edit field.</p> <p>The above fiddle is kind of that edit page which shows him old value at bottom and two fields at top. He does not know html so he thought we have changed his name in input fields however I need to know</p> <p><strong>When passing text to knockout to give initial value to an input field is it possible to tell it that consider this text as html so it renders properly in input field</strong></p> <p>The other way around is to send him to <a href="http://www.w3schools.com/tags/ref_entities.asp" rel="nofollow">http://www.w3schools.com/tags/ref_entities.asp</a> and tell him about reserved HTML characters. This info has been stored in database (using Entity Framework simple person.fname and person.lname both with attribute AllowHTML) so on my fiddle i have just placed it in two variables and you can see how actual text boxes are different than html below. If i dont bind using Knockout then actual text is shown in these boxes and user can edit <code>&lt;&gt;'</code> signs without any problem.</p> <p>Anyone with a solution before he leaves our planet. This can change alien life on our planet.</p> <p><strong>Update</strong> If i go into this field and paste <code>(~'@@~&gt;?&lt;+!""*%$)"</code> binding works fine and you can copy this and paste it into fiddle to see that. However its not taking that value from Javascript variable to knockout expects it to be a string and html special characters are not shown properly in input field.</p> <p>We have done another test without Knockout and this text does get rendered within the field when you try to edit it its fine.</p> <p>We have updated JSfiddle to work without JQuery and its the same result if you store it in a js variable and give not value to input field</p> <p><a href="http://jsfiddle.net/farrukhsubhani/3RjRF/3/" rel="nofollow">http://jsfiddle.net/farrukhsubhani/3RjRF/3/</a> </p> <p>If we assign value to input field and just use jQuery to populate fullname then it works</p> <p><a href="http://jsfiddle.net/farrukhsubhani/3RjRF/4/" rel="nofollow">http://jsfiddle.net/farrukhsubhani/3RjRF/4/</a></p> <p>This last fiddle is a working example and we want Knockout to do what JQuery is doing. </p> <p>I think the question then comes to how can this text be stored in javascript variable and placed into input field as html text so special characters appear unescaped. You can try unescape on jsfiddle that did not work for us.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload