I have a function which gets input from a set of input field and stores them as an object like this:
getinput:function () {
return{
type:document.querySelector(domstring.type).value,
description:document.querySelector(domstring.description).value,
value:document.querySelector(domstring.value).value,
heading:document.querySelector(domstring.heading).innerHTML,
}
},
Here domstring is another object which contains the class names of the target fields. Now I wrote a clearfields function and what I am trying to do is to access the type object which is a document.querySelector(domstring.type).value and set it to "" so that value is cleared.Here the base iife is called UIcontroller hence I am accessing as UIcontroller.getinput().description so UIcontroller looks like this :
var UIcontroller=(function (){
domstring={
type:'.add__type',
description:'.add__description',
value:'.add__value',
add__btn:".add__btn",
heading:".icome__title",
income_section:".income__list",
expense_section:".expenses__list"
}
return{
getinput:function () {
return{
type:document.querySelector(domstring.type).value,
description:document.querySelector(domstring.description).value,
value:document.querySelector(domstring.value).value,
heading:document.querySelector(domstring.heading).innerHTML,
}
},
getdom:function () {
return domstring
},
display:function (r,type) {
var html,newHTML,element;
if (type=='inc') {
element=domstring.income_section;
html="<div class='item clearfix' id='income-0'><div class='item__description'>%description%</div><div class='right clearfix'><div class='item__value'>%valu%</div><div class='item__delete'><button class='item__delete--btn'><i class='ion-ios-close-outline'></i></button></div></div></div>";
}
else {
element=domstring.expense_section;
html="<div class='item clearfix' id='income-0'><div class='item__description'>%description%</div><div class='right clearfix'><div class='item__value'>%valu%</div><div class='item__delete'><button class='item__delete--btn'><i class='ion-ios-close-outline'></i></button></div></div></div>";
}
newHTML=html.replace("%description%",r.description);
newHTML=newHTML.replace("%valu%",r.valu);
document.querySelector(element).insertAdjacentHTML('beforeend',newHTML);
},
clearfields:function () {
console.log("Clear");
UIcontroller.getinput().description="";
console.log(UIcontroller.getinput().description);
document.querySelector(domstring.value).value="";
}
}
})();
I tried the following way:
clearfields:function () {
console.log("Clear");
//first one
UIcontroller.getinput().description="";
//second one
document.querySelector(domstring.value).value="";
} I understand that first one and second one are basically the same right but first one does not set to blank however second one works fine. Can somebody explain.