jQuery(function($) {
$('form#survey-7').bind('submit', function() { $('#submit').attr("disabled", true); });
$(':input.Other').bind('click', function() { $(this).prev().prev().attr("checked", "checked"); });
// set the default survey error handler $.fn.form.setErrorHandler('default', function(errors) { var form = $(this);
// remove the error messages form.find('.Widget div.Error').remove();
// foreach error, insert them $.each(errors, function(errorIndex, error) { // fields with the same name represent radio and checkboxes var fieldsWithSameName = form.find('[name="' + error.field.attr('name') + '"]');
// put a error message after the widget title, but do it only once for each widget if (fieldsWithSameName.index(error.field) == fieldsWithSameName.length - 1) { //error.field.closest('.Widget').find('label:first').after('
'); error.field.closest('.Widget').find('label:first').after('
'); } });
// focus the first error field errors[0].field.focus();
// and alert the first error message alert(errors[0].message); $('#submit').removeAttr("disabled"); });
// initialize the survey validator $('#survey-7').form().init({ errorClass : 'Required' });
$('#survey-7').form().getFields().each(function() { var field = $(this); var label = field.closest('.Widget').find('label:first'); flabel = label.text(); flabel = flabel.replace(" *","""); field.form().setErrorMessage('required', 'The "' + flabel + ' field is required.'); });
// language pack the error messages $('#survey-7').form().setErrorMessage('required', "This field is required.");
// "Other" fields must not be empty if their corresponding // radio button is checked $('#survey-7 :input.Other').form().setDependency(function(field) { if ($(this).siblings(':radio:checked, :checkbox:checked').length && $.trim($(this).val()) == '') { $('#submit').removeAttr("disabled"); return false; } return true; }, "Please type an answer in the text box next to the checked field.");
// disabling button on submit //alert( $('.required:first').form().getErrorMessage() ); });



No comments yet.