javascript - this is defined, but children and querySelector fail for custom element -
i have custom element (input-date) inside custom element (edit-table). when go assign value input-date, inside 'set value' class member function log:
console.log(this)
prints out element
<input-date id="cell" style="height: 100%; width: 300px;"> <input id="input" placeholder="mm/dd/yyyy, hh:mm am/pm" style="font-family: "open sans", sans-serif; height: 100%; width: 100%; text-align: left; font-size: 18px; border: 2px; border-radius: 5px; padding: 5px;"> </input-date>
but when do
console.log(this.children);
and
console.log(this.queryselector('#input'));
i 'null'.
the function 'this' inside 'set value' of input-date class
class inputdate extends htmlelement { ... connectedcallback() { var input = document.createelement('input'); input.id = 'input'; this.appendchild(input); } set value(val) { //val should date object var = this.queryselector('#input'); if(i && val) { i.value = val.tolocalestring(); } console.log(i,val,this, this.childnodes); } ... customelements.define('input-date',inputdate);
note: if relevant, my_date.value = some_date; (the part calls 'set value' class member function) happens in completion block xmlhttprequest api.
the input-date created inside custom element called edit-table.
so set users in 'edit-table'
get_users(function(r) { if(r.hasownproperty('error_message')) { alert(r.error_message); } else { var table = document.getelementbyid('edit-table'); table.users = r.users; } });
then under 'edit-tables' 'set users', create 'input-date' element , try assign date server, (which wed feb 08 2017 00:00:00 gmt-0500)
class editusers extends htmlelement ... set users(users) { ... var check = document.createelement('input-date'); check.value = new date('wed feb 08 2017 00:00:00 gmt-0500'); } customelements.define('edit-table',edittable); }
any ideas?
wow! cant believe it. i've been making mistake years , still doing it....
i need 'appendchild' of custom-element before doing
my_element.value = new date();
because until 'appendchild' called, 'connectedcallback()' not called yet, , therefore 'input' element not appended custom-element yet, , therefore 'queryselector' cant find child yet.
thanks @mickers, didnt want bog down details, happened. helps someone
Comments
Post a Comment