Custom checkbox add/edit

Hi,

I have a boolean type property in the task object and I'd like to add a checkbox in the general tab to set the value.

I was trying to set it to try by default and let the user uncheck it, but my code doesn't work as expected. When I add a new task and uncheck the checkbox, in the edit it's still checked.

Is there a solution to this? I know I'm doing something wrong, but I cannot find documentation about this.


I add here part of my code, I also have another custom field which works fine.

In the actionBegin method I have 

    if (args.requestType === "beforeOpenEditDialog" || args.requestType === "beforeOpenAddDialog") {
      //add the status dropdown
      var column = this.ganttInstance.columnByField["Status"];
      this.divElement = this.ganttInstance.createElement("div", {
        className: "e-edit-form-column"
      });
      var inputElement;
      inputElement = this.ganttInstance.createElement("input", {
        attrs: {
          type: "text",
          id: this.ganttInstance.controlId + "" + column.field,
          name: column.field,
          title: column.field
        }
      });
      this.divElement.appendChild(inputElement);
      var input = {
        enabled: true,
        floatLabelType: "Auto",
        placeholder: "Stato",
        value: args.rowData.Status ? args.rowData.Status : this.Statuses[0],
        dataSource: this.Statuses
      };
      var inputObj = new this.inputs[column.editType](input);
      inputObj.appendTo(inputElement);


      //add the notification checkbox
      var notificationColumn = this.ganttInstance.columnByField["Notification"];

      this.divElement2 = this.ganttInstance.createElement("div", {
        className: "e-edit-form-column"
      });

      var notificationCheckboxElement;
      notificationCheckboxElement = this.ganttInstance.createElement("input", {
        attrs: {
          type: "checkbox",
          label: "Notifica",
          id: this.ganttInstance.controlId + "" + notificationColumn.field,
          name: notificationColumn.field,
          title: notificationColumn.field
        }
      });

      if (args.requestType === "beforeOpenEditDialog") {
        args.rowData.Notification = args.rowData.Notification === true;
      } else {
        args.rowData.Notification = true;
      }
      this.tempNotification = args.rowData.Notification;
     
      this.divElement2.appendChild(notificationCheckboxElement);
      var notificationCheckbox: CheckBoxModel = {
        label: "Notifica",
        value: args.rowData.Notification,
        checked: args.requestType === "beforeOpenEditDialog"?args.rowData.Notification:true,
        change: (args: any) => { this.tempNotification = args.checked; }
      };

      var notificationCheckboxObj = new this.inputs[notificationColumn.editType](notificationCheckbox);
      notificationCheckboxObj.appendTo(notificationCheckboxElement);

And in the beforeAdd I do this:

      let Notification = this.tempNotification;
      args.newTaskData.Notification = this.tempNotification;

While in the beforeSave:
      let Notification = this.tempNotification;
      args.modifiedTaskData[0].modifiedTaskData.Notification = this.tempNotification;

Thank you in advance if you have a solution.
Matteo Messmer

3 Replies 1 reply marked as answer

PS Premkumar Sudalaimuthu Syncfusion Team April 6, 2022 02:48 PM UTC

Hi Matteo ,


We have prepared an example for uncheck and check the checkbox on condition basis. By using the checked property on condition basis we can able to achieve your requirement. We have shared sample and code snippets for your reference.


Code snippets:


var input = {

        enabled: true,

        checked:

          args.requestType === 'beforeOpenAddDialog'

            ? true

            : args.rowData.customcheckbox,

        floatLabelType: 'Auto',

        placeholder: 'customcheckbox',

        value: args.rowData.customcheckbox,

      };

      var inputObj = new inputs[column.editType](input);

      inputObj.appendTo(inputElement);

 


Sample: https://stackblitz.com/edit/5vpodp-va2fvq?file=index.js


Regards,

Premkumar S


Marked as answer

MA matteomessmer April 6, 2022 04:50 PM UTC

Thank you very much, I managed to make it work with your code


Matteo Messmer



PS Premkumar Sudalaimuthu Syncfusion Team April 7, 2022 09:55 AM UTC

Hi Matteo,


You are welcome. Please contact us if you need any further assistance.


Regards,

Premkumar S



Loader.
Up arrow icon