Meteor.js hidden input on form gets blank when populating with same value -


i had in template called "todo_form":

<input type="hidden" id="priority" value="{{todo.priority}}"> 

i had "rendered" callback setup on form read value hidden input, , setup jquery ui slider it. form populated clicking on todo list (via registered session var, "active_todo").

so, if click todo priority of 10, , click other todo same priority $('#priority').val() return blank... worked fine long clicked on todo different priority. verified using console - field getting set blank!

my solution instead check registered "active_todo" , pull priority it, had update hidden input: $("#priority").val(active_todo.priority).

anybody got ideas? here's original (non working) rendered callback:

template.todo_form.rendered = ->     priority = $( "#priority" ).val();     $( "#priority-slider" ).slider(         range: "min"         value: priority         min: 1         max: 10         orientation: 'vertical'         slide: ( event, ui ) ->             $( "#priority" ).val( ui.value)     ) 

and here how "fixed" it:

template.todo_form.rendered = ->     active_todo = session.get('active_todo');     $("#priority-slider" ).slider(         range: "min"         value: active_todo.priority         min: 1         max: 10         orientation: 'vertical'         slide: ( event, ui ) ->             $("#priority").val( ui.value)     )     $("#priority").val(active_todo.priority) # shouldn't have this!!! 

it's bit difficult understand you're trying accomplish, believe want have slider value shows priority of selected todo item, , want make possible change value slider.

if so, hidden input isn't necessary. need make "current todo" reactive data source. , have "active_todo" session variable. here's suggest, in javascript (this on-the-fly , untested):

var priocomp;  template.todo_form.rendered = function() {   $("#priority-slider").slider({     range: 'min',     value: 1,     min: 1,     max: 10     start: function() {        priocomp.stop();     },     stop: function(event, ui) {         session.get('active_todo').priority = ui.value;       trackpriority();     }   });   trackpriority(); };  function trackpriority () {   priocomp = deps.autorun(function() {     $("#priority-slider").slider('value', session.get('active_todo').priority);   });     } 

like said, untested, maybe bug or 2 in here, @ least @ code , try understand i'm attempting.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -