1

i am using jsrender and i got issue on accessing value

{{for items}}
  <input type="text" id="id1" value="{{*: Json.stringify(data)}}" />
{{/for}}

here i got value as: "{" id":"1","name":"johnny depp"}"

$("#id1").val() gives '{' all other values trimmed and

<input type="text" id="id1" value={{*: Json.stringify(data)}} />

here i get: "{id":"1","name":"johnny" depp"}

$("#id1").val() gives '{id":"1","name":"johnny'

the words after the space is getting trimmed how can i show full value

i have tried the solution as in <input value={{:abc}} /> does not seem to work properly in jsviews if the value of 'abc' has whitespace but still not working

  • issue is with double quotes i have tried with custom function so when ever doubles quotes passed only values inside first starting and closing quotes is taken all other will be ommited – user17796303 Oct 25 '22 at 12:43

1 Answers1

1

Since the string returned from stringify() includes double quotes ", you need to instead use single quotes ' for the value='...' on the markup for the input:

<input type="text" id="id1" value='{{*: JSON.stringify(data)}}' />

which will give

<input type="text" id="id1" value='{"id":"1","name":"johnny depp"}' />

Now $("#id1").val() will give: '{"id":"1","name":"johnny depp"}'

BorisMoore
  • 8,444
  • 1
  • 16
  • 27