0

In my Application (ExtJS 4.2.1) I have a window for creating a new record and save it to database.

When I create the window and show it I create a new record and assign it to the window form record:

 onNewPunchClick: function(button, e, options) {
        var me = this;

        var win = Ext.create('App.view.attendance.punch.EditPunch'),
            editForm = win.down('#editForm');

        var newRec = Ext.create('App.model.attendance.DailyTime', {
            AttendanceId: 0,
            EmployeeId: 0,
            SensorId: 0,
            IsManual: true,
            IsActive: true
        });

        // load record to form
        editForm.loadRecord(newRec);

        win.show();
    },

Then my form is displayed but some fields has "0" like this:

enter image description here

So I was trying to workaround but I can't get it working fine:

I have tried using the convert function in the model that returns ' ' when 0 value.

I also have tried to use the defaultValue in the model without any success.

I also have tried to set EmployeeId: '', when creating the model with no success.

There should something that I'm missing, any help is really appreciated.

Community
  • 1
  • 1
VAAA
  • 14,531
  • 28
  • 130
  • 253
  • It's been a while since I was heavy into ExtJS development but I had the same problem with all of our tables that we kept drop down information for. If you linked them by id, they always showed 0 instead of no value when they were not yet set. I ended up setting the type to string in the model and that alleviated the problem for me. Maybe that could work for you as well? My web service was pretty forgiving of the type of data that came back so that wasn't a huge problem but maybe that's not the case for you? – Stephen Tremaine Jul 29 '14 at 17:54
  • Just post the solution that I figure out. – VAAA Jul 29 '14 at 18:04
  • Just deleted, it works but when you try to change the value of a field its not reflected in the model. – VAAA Jul 29 '14 at 18:07

1 Answers1

0

The solution that works great is:

In your model set the property that you want to have the desired behavior like this:

{ name: 'EmployeeId', type: 'int', defaultValue: '', convert: null },

Then when you create the model set the property to undefined.

var newRecord = Ext.create('CustomModel',{
    EmployeeId: undefined
});

Then load the form:

form.loadRecord(newRecord);

And after you submit the form:

form.updateRecord(newRecord);
VAAA
  • 14,531
  • 28
  • 130
  • 253