Front-End custom createView can not setFieldNotReadOnly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trungtvmso
    Member
    • Jun 2022
    • 70

    Front-End custom createView can not setFieldNotReadOnly

    Hi all,

    I'm trying to createView to Edit Lead Record with Field condition by role. I'm looking for the way to set Field to not readonly after click my custom button to createView Edit But It doesn't work anyway. Can you pls help me to do it.

    This is my custom code to extend detail view of Lead Entity

    PHP Code:
    
    define('custom:views/lead/detail', ['views/detail','moment'], function (Dep, Moment) {
        return Dep.extend({
            setup: function () {
                Dep.prototype.setup.call(this);  
                // console.log(this);    
                this.addMenuItem('buttons',{
                    name: 'superEdit',
                    text: this.translate('Edit', 'labels' , 'Lead'),
                    acl: 'edit',
                    hidden: true,
                    style: 'success',
                    action: 'superEdit',
                });
                /* Connected */
                this.hideHeaderActionItem('convert');
                this.hideHeaderActionItem('unfollow');
                this.hideHeaderActionItem('follow');
                this.listenTo(this.model, 'sync' ,() => this.hideHeaderActionItem('follow'));
                this.listenTo(this.model, 'sync' ,() => this.hideHeaderActionItem('unfollow'));
                this.controlSuperEditButton();
                this.listenTo(this.model, 'sync',() => this.controlSuperEditButton());
            },
            /* Action template */
            controlSuperEditButton: function () {
                let dateEnd = this.model.get('editEndedAt');
                let checkDate = this.getDateTime()
                .toMoment(dateEnd)
                .isBefore(moment.now());
                if (checkDate) {
                    this.updateMenuItem('superEdit', {
                        hidden: false,
                    });
                }
            },
            actionSuperEdit: function () {
              
                var Lead = this.getMetadata().get('clientDefs.Lead.modelViews.edit') || 'views/modals/edit';
                this.createView('LeadSuperEdit', Lead, {
                    scope: 'Lead',
                    fullFormDisabled: true,
                    headerText: this.translate('Edit', 'labels' , 'Lead') + ' → '+ this.model.get('name'),
                    backdrop: false,
                    id: this.model.get('id'),
                },(view) => {
                    view.render(() => {
                        console.log("View Setup", view);
                        view.setFieldNotReadOnly('source',true); // ALWAYS RECEIVE ALERT THAT THIS IS NOT A FUNCTION
                    });
                    view.notify(false);
                    view.once('after:save', models => {
                            view.close();
                            this.model.fetch();
                    });
                });
            },
          
        });
    });
    

    ALWAYS RECEIVE ALERT THAT THIS IS NOT A FUNCTION
    PHP Code:
    view.render(() => {
                        console.log("View Setup", view);
                        view.setFieldNotReadOnly('source',true);
                    });
    Last edited by trungtvmso; 07-19-2024, 03:49 AM.
  • yuri
    Member
    • Mar 2014
    • 8455

    #2
    Wrong forum category. Should be posted in Developer Help. I moved your another post yesterday. Moving posts is also work that takes time.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • trungtvmso
      trungtvmso commented
      Editing a comment
      Very sorry Yuri because of my mistake. I will not post in wrong category anymore. Once again, i'm very sorry
  • yuri
    Member
    • Mar 2014
    • 8455

    #3
    views/modals/edit does not have this method: https://github.com/espocrm/espocrm/b...ls/edit.js#L29

    But you can obtain the list view with getRecordView() method.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment


    • trungtvmso
      trungtvmso commented
      Editing a comment
      So we can not change readOnly field into edit mode when open in view/modals/edit. Am I right, sir?

    • yuri
      yuri commented
      Editing a comment
      Not right. You have access to the list view with getRecordView, so you can.
  • trungtvmso
    Member
    • Jun 2022
    • 70

    #4
    I did resolved this by another way.

    I've just relized that we can set readOnly or Edit each field by role instead of using code. The consql when you worked hard in code over 180 mins per each day. LOL

    Comment

    Working...