问题
I've been working on the validation of a form using AlloyUI/Yui, but I have the following problem: I have 3 input fields that are for the date of birth, they are all required so when I click the submit button I get 3 "this field is required" messages that are breaking my layout. Is there a way to make the script show only one message instead of 3?
I have a jsfiddle (http://jsfiddle.net/0yak4z07/9/) showing the issue. The code is pasted below too:
YUI().use('aui-form-validator', function (Y) {
var rules = {
_mine_WAR_portlet_dd: {
required: true,
digits: true,
maxLength: 2,
range: [1, 31]
},
_mine_WAR_portlet_mm: {
required: true,
digits: true,
maxLength: 2,
range: [1, 12]
},
_mine_WAR_portlet_yyyy: {
required: true,
digits: true,
maxLength: 4,
range: [1900, 2014]
},
};
var fieldStrings = {
_mine_WAR_portlet_dd: {
required: 'Required',
},
_mine_WAR_portlet_mm: {
required: 'Required',
},
_mine_WAR_portlet_yyyy: {
required: 'Required',
}
};
var form = Y.one('.formValidator');
if (form != null && form != '' && form != undefined) {
new Y.FormValidator({
boundingBox: '.formValidator',
fieldStrings: fieldStrings,
rules: rules
});
}
});
来源:https://stackoverflow.com/questions/27953713/yui-input-group-validation