Search code examples
extjsextjs6extjs6-modern

ExtJS 6.7 Modern - Define unchecked value for a checkbox


Is there is an easy way to define unchecked value for a checkbox in ExtJS 6.7 modern toolkit? Like Ext.form.field.Checkbox.uncheckedValue in classic toolkit.

At the first glance I should override Ext.form.field.Checkbox or use Ext.data.writer.Writer.transform in modern and it seems like overkill for me.


Solution

  • In modern toolkit - there isn't uncheckedValue in checkboxfield.

    I guess you're using record.set(form.getValues()); and next store.sync() so you can do what you said (override checkbox or use Ext.data.writer.Writer.transform) or you can use serialize in model.

    A function which converts the Model's value for this Field into a form which can be used by whatever Ext.data.writer.Writer is being used to sync data with the server.

    Example:

     Ext.define('App.model.Test', {
          fields: [{ 
               name: 'status', 
               type: 'auto',
               serialize: function (value, record) {
                    if(value === 1){
                         return "success";
                    } else {
                         return "failed";
                    }
               }
          }]
     });