Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load or set value in tagfield

I am using a tagfield as a widget column. I am selecting few values from drop down and then saving it. Again when I open I wanted my selected value should be present there in tagfield. It is only coming only after tagfield getting focused.

What I am trying here is, My Code :

 var SValue = XML.getAttribute('value');

if(filterType.xtype == "tagfield"){
        filterType.setValue(SValue); // This is not working
        filterField.inputEl.set({'placeholder':SValue}); // This is working but not correct way to do.
    }

I used placeholder it somewhat showing values but this is not correct what I want. Can anyone suggest me what I can do here. If it is getting automatically focused then also there is chance to work.

Note : In another word its like how to load or set the value to tagfield by reading particular attribute from XML.

like image 711
David Avatar asked Mar 09 '17 07:03

David


1 Answers

There are two possible scenarios to this:

  • If the queryMode for the tagfield is equal to 'local' then tagfield.setValue({valueField}) should work. If it is not working, it is probably because you are not using the right valueField. So, if you set valueField: 'id' then this is how you should set the value of the tagfield tagfield.setValue(record.data.id)

  • If your queryMode for the tagfield is equal to 'remote' then you first have to add the record to the tagfields store and then set the value to the valueField that you set on the tagfield.

let newRec = {value: 'lorem', id: '1'};
tagfield.getStore().add(newRec);
//suppose our valueField for the tagfield is 'id'
tagfield.setValue(newRec.id);

You can also load the tagfield's store with the necessary data, and then set the value and that should also work.

Store documentation Tagfield documentation

like image 99
Diana Avatar answered Sep 22 '22 05:09

Diana