I found the answer I was looking for. The version I was using, did not have a cancel method when using $.observable, and or updating the properties. Solution here:
When I am in the modal to change the settings of the property, I set a global property, so that the onBeforeChange event returns false. I then do my validation on the new value the user entered. If it passes validation, I then update it via observable, setProperty, and then switch off the global setting. This allows the biding to update accordingly in the view, but not update before validation occur.
An example, simple example, of this can be found in the following
<table><tbody id="pageList"></tbody></table>
//template for the table
<script id="pageTmpl" type="text/x-jsrender">
{^{for pages}}
<tr>
<td data-link="name"></td>
<td>
<input data-link="name" class="page-names"/>
</td>
<td>
<button id="save" class="saveCmd">Save</button>
<button id="cancel" class='cancelCmd'>Cancel</button>
</td>
</tr>
{{/for}}
</script>
And the javascript to push it:
var isModal = true;
$.views.helpers({
onBeforeChange: function(ev, data)
{
//this would be global setting if in a modal
if(isModal)
{
return false;
}
},
onAfterChange: function (ev, data)
{
//this would be global setting if in a modal
if(isModal)
{
return false;
}
}
});
$(document).ready(function(){
//not used at moment!!!
$(".saveCmd").on("click", function(){
var dataItem = $.view(this).data,
newVal = $(this).parent().parent().find('input').val();
//validate newValue
if(!ValueIsValid(newVal))
{
alert("Must be 10 characters or less!");
}
else
{
isModal = false;
$.observable(dataItem).setProperty("name", newVal);
isModal = true;
}
});
$(".cancelCmd").on("click", function(){
var dataItem = $.view(this).data;
$(this).parent().parent().find('input').val(dataItem.name);
});
});
//KETHCUP VALIDATION FUNCTION mock example
function ValueIsValid(val)
{
return val.length < 11;
}
//variables and setup for initial objec.
var myTemplate = $.templates("#pageTmpl");
var pages = [
{
name: "Q100"
},
{
name: "Q200"
}
];
var app = {
pages: pages
};
var counter = 1;
myTemplate.link("#pageList", app);
link to demo at fiddle: http://jsfiddle.net/Duj3F/171/