File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ Find the controls in element and children elements and binding it.
8282
8383#### Arguments
8484
85- 1 . ` element ` (** ? HTMLElement** ) HTMLElement for binding. The ` BODY ` element as a default .
85+ 1 . ` element ` (** HTMLElement** ) HTMLElement for binding.
8686
8787#### Returns
8888
@@ -97,7 +97,7 @@ controller:
9797Controller .registerControl (' form-date' , element => $ (element).datepicker ({dateFormat: ' yy-mm-dd' }));
9898
9999document .addEventListener (' DOMContentLoaded' , function () {
100- Controller .bind () ; // bind datepicker control
100+ Controller .bind (document . getElementsByTagName ( ' body ' )[ 0 ]) ; // find input and bind datepicker control to it
101101});
102102```
103103
@@ -196,7 +196,7 @@ Controller.registerControls({
196196 ' form-date ' : element => $ (element).datepicker ({dateFormat: ' yy-mm-dd' }),
197197 ' append ' : element => new AppendControl (element),
198198});
199- Controller .bind ();
199+ Controller .bind (document . getElementsByTagName ( ' body ' )[ 0 ] );
200200```
201201
202202Use in HTML:
Original file line number Diff line number Diff line change 6868 * @returns {boolean }
6969 */
7070 static singleBind ( element ) {
71+ if ( ! ( element instanceof HTMLElement ) ) {
72+ throw new Error ( `The element to be binding must be instance of HTMLElement, now it is "${ typeof element } ".` ) ;
73+ }
74+
7175 if ( ! element . getAttribute ( 'data-control' ) ) {
7276 return false ;
7377 }
8993
9094 /**
9195 * Find the controls in element and children elements and binding it.
92- * @param {? HTMLElement } [ element=null]
96+ * @param {HTMLElement } element
9397 * @returns {boolean }
9498 */
9599 static bind ( element ) {
96- element = element || document . getElementsByTagName ( 'body' ) [ 0 ] ;
100+ if ( ! ( element instanceof HTMLElement ) ) {
101+ throw new Error ( `The element to be binding must be instance of HTMLElement, now it is "${ typeof element } ".` ) ;
102+ }
97103
98104 let binded = Controller . singleBind ( element ) ;
99105
You can’t perform that action at this time.
0 commit comments