Well, I know that the first thought here for everyone is to simply create another validation method and message. But here is the deal. We have a form in which there is a field that is used as the name of the artist and the name of the company, depending on what is selected in the drop-down list.
What I need to do is when the drop-down list shows that they belong to the company and they do not fill in the field, and then show one message. If they do not belong to the company and it is empty, then it displays a different message.
How would I do that? This uses the latest jQuery and the Validate plugin ( http://jqueryvalidation.org/ ).
UPDATE: I present to you the code that I finished after selecting the selected answer below ...
http://pastebin.com/iG3Z4BbJ
Thanks and enjoy!
Detailed code:
/** * Reference: http://jqueryvalidation.org/rules */ $(document).ready(function() { var rules = { IncomeSource: 'required', NetIncome: { required: true, usDollar: true, minDollars: 1 }, //Begin - Fields that don't always show JobTitle: { //required: true, nameInput: true }, Employer: { //required: true, nameInput: true }, EmployerPhone: { //required: true, phoneUS: true }, BenefitSource: { //required: true, nameInput: true }, //SemiMonthlySpecifics: 'required', //Select one when Semi-Monthly or Monthly are selected //End - Fields that don't always show PayFrequency: 'required', LastPayDate: { required: true, pastDate: true, date: true }, NextPayDate: { required: true, futureDate: true, date: true }, DirectDeposit: 'required', EmploymentLength: 'required', ActiveMilitary: 'required', RoutingNumber: { required: true, digits: true, rangelength: [9, 9] }, AccountNumber: { required: true, digits: true, rangelength: [4, 17] }, AccountType: 'required' }; //And field specific (and even validation type specific) error messages var messages = { IncomeSource: ss.i18n._t('IncomeSourceRequiredError'), NetIncome: { required: ss.i18n._t('NetIncomeRequiredError') }, //Begin - Fields that don't always show JobTitle: { required: ss.i18n._t('JobTitleRequiredError') }, Employer: { required: ss.i18n._t('EmployerRequiredError') }, EmployerPhone: { required: ss.i18n._t('EmployerPhoneRequiredError') }, BenefitSource: { required: ss.i18n._t('BenefitSourceRequiredError') }, SemiMonthlySpecifics: ss.i18n._t('SemiMonthlySpecificsRequiredError'), //Select one when Semi-Monthly or Monthly are selected //End - Fields that don't always show PayFrequency: ss.i18n._t('PayFrequencyRequiredError'), LastPayDate: { required: ss.i18n._t('LastPayDateRequiredError') }, NextPayDate: { required: ss.i18n._t('NextPayDateRequiredError') }, DirectDeposit: ss.i18n._t('DirectDepositRequiredError'), EmploymentLength: ss.i18n._t('EmploymentLengthRequiredError'), ActiveMilitary: ss.i18n._t('ActiveMilitaryRequiredError'), RoutingNumber: { required: ss.i18n._t('RoutingNumberRequiredError') }, AccountNumber: { required: ss.i18n._t('AccountNumberRequiredError') }, AccountType: ss.i18n._t('AccountTypeRequiredError') }; $('#applicationForm').validate({ //debug: true, rules: rules, messages: messages, errorElement: 'span', ignore: '.ignore', onfocusout: function( element, event ) { $(element).valid(); }, invalidHandler: function(event, validator) { kclHelpers.openErrorModal(event, validator); }, errorPlacement: function(error, element) { var insertLocation = kclHelpers.getInsertLocation(element); error.appendTo( insertLocation ); }, success: function(label, element) { element = $(element); var insertLocation = kclHelpers.getInsertLocation(element); insertLocation.hide(); kclHelpers.parentShowSuccess(element, '.control-group'); }, //Had to use this for show/hide of errors because error placement doesn't get called on every error. showErrors: function(errorMap, errorList) { if (this.numberOfInvalids() > 0) { //We want to make sure that we show/hide things appropriately on error $.each(errorList, function(index, item) { var domElement = item['element']; var message = item['message']; var element = $(domElement); var insertLocation = kclHelpers.getInsertLocation(element); insertLocation.show(); kclHelpers.parentShowError(element, '.control-group'); }); } this.defaultShowErrors(); } }); $('[rel=tooltip]').tooltip(); // When the income source is changed, change the form respectively $('