I'm having a difficult time figuring out how to do this. I have a KnockoutJS viewmodel attached to a table of inputs. When the first input in each row blurs, I pop up a modal asking the user a question. If they answer 'no', the focus needs to go back to the original input. If 'yes', the focus should jump to the next input in the row. I'm not sure how to pass along the input ID from knockoutJS into the modal and back out again. Or if there is a better way to do it.
HTML for the input with blur function:
<td data-bind="css: { highlighted: $root.highlightedRowIndex() == $index() }">
<input type="text" data-bind="value: itemNo, insertPress: $index, deletePress: $index, hasFocus: invalidItemNum, selected: invalidItemNum, event: { blur: function(){ $parent.checkItemNo($data, $index); } }, attr: { name: 'sellerItems[' + $index() + '].itemNo', id: 'sellerItems_' + $index() + '__itemNo', tabindex: 5 + $index() }" class="form-control" />
</td>
And the associated KO:
self.checkItemNo = function(data, index) {
console.log(data);
var itemNo = $.trim(data.itemNo());
if(verify == "False") {
......
} else {
if(!foundItem && itemNo != "") {
$('#invalidItemMsg').html("Item number <strong>" + itemNo + "</strong> is not a valid item number. Would you like to report it?")
$('#invalidItemNum').val(itemNo);
$('#invalidItemModal').modal('show');
}
}
};
And then my JS modal button click event(the 'yes' button in the modal):
$('#reportItem').click(function() {
$('#invalidItemModal').modal('hide');
// ??? - go to next knockout input from previous input that was blurred
});