File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
src/bundle/Resources/public/js/scripts/fieldType Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ ( function ( global , doc , ibexa ) {
2+ const SELECTOR_FIELD = '.ibexa-field-edit--ezisbn' ;
3+ const SELECTOR_SOURCE_INPUT = '.ibexa-data-source__input' ;
4+ const SELECTOR_LABEL = '.ibexa-field-edit__label' ;
5+
6+ class IbexaIsbnValidator extends ibexa . BaseFieldValidator {
7+ /**
8+ * Validates the input
9+ *
10+ * @method validateInput
11+ * @param {Event } event
12+ * @returns {Object }
13+ * @memberof IbexaIsbnValidator
14+ */
15+ validateInput ( event ) {
16+ const isError = event . target . required && ! event . target . value . trim ( ) ;
17+ const label = event . target . closest ( SELECTOR_FIELD ) . querySelector ( SELECTOR_LABEL ) . innerText ;
18+ const errorMessage = ibexa . errors . emptyField . replace ( '{fieldName}' , label ) ;
19+
20+ return {
21+ isError,
22+ errorMessage,
23+ } ;
24+ }
25+ }
26+
27+ const validator = new IbexaIsbnValidator ( {
28+ classInvalid : 'is-invalid' ,
29+ fieldSelector : SELECTOR_FIELD ,
30+ eventsMap : [
31+ {
32+ selector : `${ SELECTOR_FIELD } input` ,
33+ eventName : 'blur' ,
34+ callback : 'validateInput' ,
35+ errorNodeSelectors : [ '.ibexa-form-error' ] ,
36+ invalidStateSelectors : [ SELECTOR_SOURCE_INPUT , SELECTOR_LABEL ] ,
37+ } ,
38+ ] ,
39+ } ) ;
40+
41+ validator . init ( ) ;
42+
43+ ibexa . addConfig ( 'fieldTypeValidators' , [ validator ] , true ) ;
44+ } ) ( window , window . document , window . ibexa ) ;
You can’t perform that action at this time.
0 commit comments