99 class CrudField {
1010 constructor (name ) {
1111 this .name = name;
12- this .$input = $ (' input[name="' + this .name + ' "], textarea[name="' + this .name + ' "], select[name="' + this .name + ' "],select[name="' + this .name + ' []"]' ).first ();
13-
14- // get the wraper from the field input or find it in page.
12+
13+ // get the input/textarea/select that has that field name
14+ this .$input = $ (' input[name="' + this .name + ' "], textarea[name="' + this .name + ' "], select[name="' + this .name + ' "], select[name="' + this .name + ' []"]' ).first ();
15+
16+ // get the field wraper
1517 this .wrapper = this .inputWrapper ;
1618
17- // we still need to check if the input was overriden by setting up `bp-field-main-input` on some other element.
19+ // in case `bp-field-main-input` is specified on a field input, use that one as input
1820 this .$input = this .mainInput ;
1921
2022 // Validate that the wrapper has been found
@@ -36,25 +38,27 @@ class CrudField {
3638
3739 get mainInput () {
3840 let input = this .wrapper .find (' [bp-field-main-input]' ).first ();
39- // if a main input has been specified by developer, use it.
40- if (input .length !== 0 ) {
41+
42+ // if a bp-field-main-input has been specified by developer, that's it, use that one
43+ if (input .length !== 0 ) {
4144 return input;
4245 }
43- // if we don't have any input here, we will try to find it using other selectors or bail out using the first input on the wrapper.
44- if (this .$input .length === 0 ) {
45- // if no main input has been specified try searching for the field with the corresponding name.
46+
47+ // otherwise, try to find the input using other selectors
48+ if (this .$input .length === 0 ) {
49+ // try searching for the field with the corresponding bp-field-name
4650 input = this .wrapper .find (' input[bp-field-name="' + this .name + ' "], textarea[bp-field-name="' + this .name + ' "], select[bp-field-name="' + this .name + ' "], select[bp-field-name="' + this .name + ' []"]' ).first ();
47-
48- // if not input found yet, resort to the first input on the wrapper.
49- if (input .length === 0 ) {
51+
52+ // if not input found yet, just get the first input in that wrapper
53+ if (input .length === 0 ) {
5054 input = this .wrapper .find (' input, textarea, select' ).first ();
5155 }
5256
5357 return input;
5458 }
5559
5660 return this .$input ;
57-
61+
5862 }
5963
6064 get value () {
@@ -63,7 +67,7 @@ class CrudField {
6367
6468 get inputWrapper () {
6569 let wrapper = this .$input .closest (' [bp-field-wrapper]' );
66- if (wrapper .length === 0 ) {
70+ if (wrapper .length === 0 ) {
6771 wrapper = $ (` [bp-field-name="${ this .name } "][bp-field-wrapper]` ).first ();
6872 }
6973 return wrapper;
@@ -99,7 +103,7 @@ class CrudField {
99103 }
100104 return this ;
101105 }
102-
106+
103107 this .$input .trigger (` change` );
104108 }
105109
0 commit comments