I have a field that I am updating via a dropdown selection. When an item is chosen, it is added to the text box.
I have an onchange
value attached to the input field, but it never fires. So I am calling it myself when I call addToWorklist
, and I have to explicitly set the value of the state’s variable itself.
When I click away from the form, and then return, all the other state variables are consistent, but the input field for these values is always empty, and I’m not sure what I am doing wrong.
Here’s the view model:
<td>
Worklist(s):
<input type="text" name="worklist_list"
id="worklist_list" size="14" element.ref="state.searchObj.worklist_list"
onchange.call="worklistChanged()"
value.bind="state.searchObj.worklist_list" maxlength="50">
</td>
Here’s the addToWorklist
function where I call worklistChanged
because I can’t figure out how to fire the change event any other way.
addToWorklist() {
var d = document;
var worklistField = d.getElementById('worklist_list');
var oldWl = d.getElementById('worklist_list').value;
var newWl = this.state.searchObj.selectedWorklist;
worklistField.addEventListener('change', this.worklistChanged, false);
if ( oldWl )
{
d.getElementById('worklist_list').value = oldWl + ',' + newWl;
}
else
{
d.getElementById('worklist_list').value = newWl;
}
var newWorklistList = d.getElementById('worklist_list').value;
this.worklist_list = newWorklistList;
this.state.searchObj.selectedWorklist = null;
this.state.searchObj.worklist_list = d.getElementById('worklist_list').value;
this.worklistChanged();
//console.log('worklist_list', this.state.searchObj.worklist_list);
}
Here’s the workListChanged
function:
worklistChanged()
{
console.log('changed worklist_list', this.worklist_list);
console.log('changed worklist_list state', this.state.searchObj.worklist_list);
}
I can see that the state’s value is set, but when I come back to the form, it is empty again.
I’ve also tried subscribing to an onChanged
event through the connectTo
decorator:
@connectTo({
//target: 'currentState',
selector: (store) => store.state.pipe(pluck("wlTypeRadio")), // the complete state if you need
onChanged: 'changedHandler'
},
{ selector: (store) => store.state.pipe(pluck("potentialBadDebRadio")),
onChanged: 'setWLType'},
{ selector: (store) => store.state.pipe(pluck("worklist_list")),
onChanged: 'worklistChanged'}
)