synchronize views after change in dropdown options

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rkaranth
    Junior Member
    • Feb 2016
    • 22

    synchronize views after change in dropdown options

    Hi,
    I need to synchronize views based on options selected in drop down(enum field) in one of the custom module, once the record is saved.

    Scenario:
    1. If approved is selected in the dropdown, edit/ remove options will be disabled for non-admin users(current code as below for custom/model.js).


    isEditable: function () {
    if (!this.isNew()) {
    if (!this.getUser().isAdmin()){
    if (this.get('registrationStatus') == 'Approved') {
    return false;
    }
    }
    }
    return true;
    },

    isRemovable: function () {
    if (!this.isNew()) {
    if (!this.getUser().isAdmin()){
    if (this.get('registrationStatus') == 'Approved') {
    return false;
    }
    }
    }
    return true;
    }

    2. if rejected is selected in the dropdown, then there will be only few options pushed into the dropdown.(current code as below for custom/src/views/custom_entity/customfield.js)

    setup: function () {

    if (this.model.get('registrationStatus') == 'Rejected') {
    this.params.options = ["Pending","Incomplete","On Going","Rejected"];
    this.params.translation = 'Registration.options.registrationStatus';
    }

    Dep.prototype.setup.call(this);
    }

    For both the cases, the views are not getting synchronized/ updated immediately upon document save, and a manual refresh would be required. Any guidance or a code snippet would be helpful.
  • worldmiros
    Senior Member
    • Dec 2015
    • 120

    #2
    Are they any errors? For the 2nd one, instead of pushing down certain options, can you disabled instead, i.e. .attr('disabled','disabled'). For the first one, try ternary operator instead, i.e. !this.isNews() && !this.getUser().isAdmin() && (this.model.get("registrationStatus") == "Approved) ? false : true;

    Comment

    • rkaranth
      Junior Member
      • Feb 2016
      • 22

      #3
      There are no errors. I am getting the expected result with the above snippet. Issue is if I select "Rejected" or "Approved", and then save the record, the views are not synchronized. I will have to refresh the page to see the validation happening. I am not sure how to listen to or bind the changes done in the edit view to the detail view of the record.
      Please let me know if this explains my issue a bit clear or if you require further information.

      Comment

      Working...