Change event on TextField inside ListView Template

最后都变了- 提交于 2019-12-12 04:26:17

问题


I've a ListView Template, that has a title Label, 2 button Views (more and less) and a TextField with a value, I need to add a change event to this TextField.

<ItemTemplate name="item" id="item" bindId="item">
    <View id="row" bindId="row">
        <Label bindId="title" id="title"/>
        <View id="options" bindId="options">
            <View class="option" bindId="less" id="less"/>
            <TextField bindId="input" id="input"/>
            <View class="option" bindId="more" id="more"/>
        </View>
    </View>
</ItemTemplate>

In the change event I want to add a validation to check if the value is a number like this:

$.input.value = parseFloat(($.input.value.toString().replace(/,/g, '.')).replace(/[a-zA-Z ,_$#%&()~ºª´`'+*:;]/g,''));

The less and more buttons are working, its a simple increment/decrement, but I can't add the listener to the input, I've tried this 2 ways:

$.car.addEventListener('itemclick',function(list) {

    var row = $.car.sections[0].getItemAt(list.itemIndex);

    if(list.bindId == 'more') row.input.value++;
    if(list.bindId == 'less') row.input.value--;

    //tried this 1#: row.input.addEventListener('change',function() {});

    $.car.sections[0].updateItemAt(list.itemIndex,row);
});

//tried this 2#: $.input.addEventListener('change',function() {});

Note that I only need to use the listener when the row is clicked, every time that I change the input value or use one of the buttons, I know the index of the ListItem


回答1:


I don't know if it's the best approach, but what I'll try is to create an hidden TextField, when I click the ListItem's TextField, blur the hidden TextField, and on the change event it will update the ListItem's TextField with the same value



来源:https://stackoverflow.com/questions/38870141/change-event-on-textfield-inside-listview-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!