decide.nolog.cz/app/components/bs-form.js
Jeldrik Hanschke 3a23719127
do not rely on Array prototype extensions (#692)
* Array.any() relies on prototype extensions

* remove remaining usage of array prototype extensions
2023-10-18 14:52:57 +02:00

28 lines
780 B
JavaScript

import BaseBsForm from 'ember-bootstrap/components/bs-form';
import IntlMessage from '../utils/intl-message';
export default class BsForm extends BaseBsForm {
'__ember-bootstrap_subclass' = true;
get hasValidator() {
return true;
}
async validate(model) {
const isInvalid = Object.getOwnPropertyNames(
Object.getPrototypeOf(model),
).some((potentialValidationKey) => {
// Validation getters must be named `propertyValidation` by our convention
if (!potentialValidationKey.endsWith('Validation')) {
return false;
}
// Validation errors must be an instance of IntlMessage by convention
return model[potentialValidationKey] instanceof IntlMessage;
});
if (isInvalid) {
throw new Error();
}
}
}