-1

Please, I am using tagfield to choose the tags I want. But I don't know how to get the selected tags on the tagfield after I load the saved form. This is my code and thank you:

xtype: 'tagfield', 
fieldLabel: 'Event hour (tagfield)', 
store:  Ext.create('Ext.data.Store', { 
            fields: ['id','name'], 
            data: [{id: 0, name: 'Battlestar Galactica'}, 
                   {id: 1, name: 'Doctor Who'}, 
                   {id: 2, name: 'Farscape'}, 
                   {id: 3, name: 'Firefly'}, 
                   {id: 4, name: 'Star Trek'}, 
                   {id: 5, name: 'Star Wars: Christmas Special'}
            ] 
        }),
displayField: 'name', 
valueField: 'id',
value: [],
queryMode: 'local', 
filterPickList: true,
delimiter:",",
multiSelect: true
Y.Coding
  • 109
  • 3
  • 15
  • What do you mean selected tags. I am assuming that some pre selected tag in tagfield. When tagfield will load some value will be there ? – UDID Apr 24 '17 at 09:24
  • I mean the tags I choose from the store like in this picture: https://docs.sencha.com/extjs/5.0.1/guides/whats_new/images/tagfield.png – Y.Coding Apr 24 '17 at 10:12
  • Make `filterPickList : false` – UDID Apr 24 '17 at 10:34
  • It will be easy for us to help you if you create a fiddle on fiddle.sencha.com – Nikolai Lopin Apr 24 '17 at 10:54
  • you can just take the example in this link: http://docs.sencha.com/extjs/6.2.0/classic/Ext.form.field.Tag.html#events the only thing I want is how to get saved data chosen on the tagfield after reloading the form. I can't find any method to get them like in this link: https://docs.sencha.com/extjs/5.0.1/guides/whats_new/images/tagfield.png for example: if I choose alabama and colorado and after I save. when I reload the form. I want that choosen state to be added in the tagfield. – Y.Coding Apr 24 '17 at 11:25
  • Did you try `filterPicklist:false` ? – UDID Apr 24 '17 at 11:27
  • Yes, but it didn't work. – Y.Coding Apr 26 '17 at 14:02

1 Answers1

1

The selected items are stored as an array in the value property of the tagfield. You need to read that property and store the selected values somewhere. In order to restore the initial state of the tagfield to look like you left it simply set the previously stored array as the value config option.

See this fiddle I just put together: https://fiddle.sencha.com/#fiddle/1uhh

This should outline how to read (and store somewhere) the selection and how to preselect stuff loaded from wherever you saved it before.

For simplicity, I just stored the values comma separated in the Browser's LocalStorage. That way you can just reload the fiddle to see that it works. To see that the defaults are preselected, select different stuff in the tagfield and just reload or run the fiddle again. You should see that it didn't save the new selection and restore to the defaults. Then do the same, but hit the select button below the tagfield. If you reload now the selected state is "preserved" and preselected from LocalStorage.

Mastacheata
  • 1,866
  • 2
  • 21
  • 32