Should use "Event Handler", when I attach value to text box (readonly)?


#1

For example I have one text box with readonly style, and then I attach the value to it by click other button.
Should I use event handler for attach value checking?
Such as blur, change...


#2

You could use the button click event handler.

Template.myTemplate.events({
    'click #myCoolBtn': function() {
        $('#myCoolTxtBox').val('my_cool_new_value');
    }
});

#3

Excuse me, I want to use event on it too

'change #myText': function() {
        alert('My text is attached value');
    }

#4

Seems like onchange would be the best bet. What results are you getting
from your experiments?


#5

lets imagine that you have

<template name='myTemplate'>
	<input type='text' name='myinput'/>
	<button name='mybutton'> Attach value and handler </button>
</template>	

Template.myTemplate.events({
    'click [name=mybutton]': function(evt, tmpl) {
    	var inputEl = tmpl.find('input[name=myinput]');
    	if !inputEl return;

    	inputEl.value = 'this is tje value for input';
    	inputEl.dataset.watch = 'watch';
    },

    'input input[data-watch]': function(evt, tmpl) {
    	var inputValueIs = evt.target.value;
    }
});

#6

Look great I will try.
Thanks a lot.