// set defaults for uicForm3
$.fn.uicForm3.defaults = {
onPropertyModifiedStateChange: function (elements, name, initValue, currentValue, modified, e) {
if (modified === true) {
$(elements[0]).closest('div.property').addClass('modified');
} else {
$(elements[0]).closest('div.property').removeClass('modified');
}
},
onFormModifiedStateChange: function (modified, e) {
if (modified === true) {
$('form:eq(0)').addClass('modified');
} else {
$('form:eq(0)').removeClass('modified');
}
},
onInitDataUnload: function (initialData, formModified) {
if (formModified) {
if (confirm('Do you want to dismiss the changes of the current recordset?')) {
return true;
}
return false;
}
return true;
}
}
// apply uicForm3 to the form
$('form:eq(0)').uicForm3();
// register actions for the click event of the action buttons
$('#setInitialData').on('click', function (e) {
$('form:eq(0)').uicForm3('initData', data);
});
$('#getInitialData').on('click', function (e) {
$('#rawdata').html(syntaxHighlight(JSON.stringify($('form:eq(0)').uicForm3('data'), null, 2)));
});
// This part is less interesting. It's just the data-definition and a syntax highlighter for the json in this example that is not needed for the form handling in any way.
var data = {
account: {
id: 1,
username: 'beatles',
password: 'submarine',
users: [{
firstname: 'John',
lastname: 'Lennon'
}, {
firstname: 'Paul',
lastname: 'McCartney'
}]
}
};
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.