Our blazing fast Grid component built with pure JavaScript


Post by henrique »

I'm having a problem with the fields. When I change the field value, the record value is no longer updated.

When you click the button the message shows only the value of the updated field, but the record value has not been modified.

If you click the "Clear Error" button, and modify the field, the message shows both the same.

class Person extends Model {
   static get fields() {
      return [
         { name: "id", type: "string" },
         { name: "Order", type: "model" },
         { name: "Name", type: "string" }
      ];
   }
}

let myPerson = new Person();
myPerson.Name = "My name";

let myField = new TextField({
    appendTo : document.body,
    width    : 200,
    label    : 'Enter text',
    name : 'Name',
    style    : 'margin-right: .5em'
});

let myButton = new Button({
   text: 'My button',
   onClick: function () 
      {
          Toast.show("Field value: " + myField.value);
          Toast.show("Record value: " + myPerson.Name);
      }
});

let myButton2 = new Button({
   text: 'Clear button',
   onClick: function () 
      {
          myField.clearError();
      }
});

let MyContainer = new Container({
    appendTo : document.body,
    autoUpdateRecord: true,
    items: [myField, myButton, myButton2]
})

 MyContainer.record = myPerson;

myField.setError("My error");

Post by marcio »

Hey henrique,

Thanks for the detailed report with example, it's a bug and I created a ticket to fix it https://github.com/bryntum/support/issues/5178

Best regards,
Márcio


Post by henrique »

I did not understand the comment on the ticket that was opened


Post by mats »

It works as designed, we don't auto apply to the model if the field is invalid. Try removing:

myField.setError('My error');

And it works.


Post by henrique »

Yes, if removing it works. But the problem I have, is for example, the user puts invalid characters in the field, when he tries to save the information, I mark the field with error and put the message. Of course, the user will remove these invalid characters and try to save the information, but because the record is not updated, the validation error remains. Because validation is done in the record, not in the field that is on the screen.

One path I found to resolve is to put in the field change event, to remove the error, but the problem I have multiple fields with would have to replicate this change in various locations of my system, which makes this implementation inviable.


Post by alex.l »

Hi henrique,
Try to update record and validate in same place, as example by Save click.

All the best,
Alex


Post by henrique »

How I update the record? Can give me an example?


Post by alex.l »

All the best,
Alex


Post by henrique »

I thought it would be another function. For only one field is easy, but the problem is that I have multiple fields in multiple windows, and replicating this implementation by the entire system is unusable.


Post by alex.l »

https://bryntum.com/docs/grid/api/Core/data/Model#function-set allows to set all together, not only one field.
Field validation created to prevent set invalid data to the record. That's expected behaviour.
I think you just need to try to change your approach for validation or adopt your solution.

All the best,
Alex


Post Reply