d1cc297cd9
* Handle form validation for open api form - Added required validator for all the default fields * Fixed field group error and adedd comments * Fixed acceptance tests * Added changelog * Fix validation in edit mode - Handle read only inputs during edit mode * Minor improvements * Restrict validation only for userpass
31 lines
898 B
JavaScript
31 lines
898 B
JavaScript
import { validator, buildValidations } from 'ember-cp-validations';
|
|
|
|
/**
|
|
* Add validation on dynamic form fields generated via open api spec
|
|
* For fields grouped under default category, add the require/presence validator
|
|
* @param {Array} fieldGroups
|
|
* fieldGroups param example:
|
|
* [ { default: [{name: 'username'}, {name: 'password'}] },
|
|
* { Tokens: [{name: 'tokenBoundCidrs'}] }
|
|
* ]
|
|
* @returns ember cp validation class
|
|
*/
|
|
export default function initValidations(fieldGroups) {
|
|
let validators = {};
|
|
fieldGroups.forEach(element => {
|
|
if (element.default) {
|
|
element.default.forEach(v => {
|
|
validators[v.name] = createPresenceValidator(v.name);
|
|
});
|
|
}
|
|
});
|
|
return buildValidations(validators);
|
|
}
|
|
|
|
export const createPresenceValidator = function(label) {
|
|
return validator('presence', {
|
|
presence: true,
|
|
message: `${label} can't be blank.`,
|
|
});
|
|
};
|