How to listenTo beforeRelate

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Firyo
    Senior Member
    • Jun 2022
    • 134

    How to listenTo beforeRelate

    Hi there.

    I'm currently reworking an existing feature used in one of my extensions.
    The problem is that I can't find a way to add a
    Code:
    this.listenTo
    into my "View Setup Handler" to do exactly what I want to do.

    Here is some detail of what I'm trying to do (with the demo as example) :

    Step 1 : Open the "Select" modal to select a new "contact" (in this case) to relate to my "account" (in this case).
    Click image for larger version

Name:	image.png
Views:	344
Size:	112.1 KB
ID:	93841

    Step 2 : Select at least one contact
    (No screenshot needed)

    Step 3 : Confirm the selection and relate the "contact" to the "account"
    Click image for larger version

Name:	image.png
Views:	210
Size:	170.9 KB
ID:	93842

    Step 4 : BEFORE the AJAX is sent to the server, I want my custom code to be executed. (The custom code will be in my view setup handler).

    I hope I gave enough detail.​​
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #2
    not sure why you mean by BEFORE the AJAX is sent to the server, I want my custom code to be executed. (The custom code will be in my view setup handler) ?

    In recent version you can use a selectHandler to apply any logic you want when selecting related records.
    Rabii
    Web Dev

    Comment

    • Firyo
      Senior Member
      • Jun 2022
      • 134

      #3
      Originally posted by rabii
      not sure why you mean by BEFORE the AJAX is sent to the server, I want my custom code to be executed. (The custom code will be in my view setup handler) ?

      In recent version you can use a selectHandler to apply any logic you want when selecting related records.
      In what version was it implemented ?

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #4
        i think since version 7.4
        Rabii
        Web Dev

        Comment

        • Firyo
          Senior Member
          • Jun 2022
          • 134

          #5
          Originally posted by rabii
          i think since version 7.4
          That's why I've never seen any "selectHandler", we're still in 7.1.11.

          Is there a way of doing it without using a that ?
          I was thinking I would be able to do it using a view setup handler.

          Comment

          • rabii
            Active Community Member
            • Jun 2016
            • 1250

            #6
            the view set up handler would allow you to change a view without extending a view not sure it would be the best practical option. why not just upgrade.
            Rabii
            Web Dev

            Comment

            • Firyo
              Senior Member
              • Jun 2022
              • 134

              #7
              Originally posted by rabii
              the view set up handler would allow you to change a view without extending a view not sure it would be the best practical option. why not just upgrade.
              It's not the good period to make an upgrade like this, we intend to upgrade in september.

              Comment

              • rabii
                Active Community Member
                • Jun 2016
                • 1250

                #8
                so if i understand the you want to apply some logic once the related contacts are selected correct ?
                Rabii
                Web Dev

                Comment

                • Firyo
                  Senior Member
                  • Jun 2022
                  • 134

                  #9
                  Originally posted by rabii
                  so if i understand the you want to apply some logic once the related contacts are selected correct ?
                  I want to apply a front-end (JS) logic BEFORE the request (which will relate the contact and account together) is sent to the server.

                  Like a "beforeRelate" but in the JS not in the PHP.​

                  Comment

                  • rabii
                    Active Community Member
                    • Jun 2016
                    • 1250

                    #10
                    you can extend this https://github.com/espocrm/espocrm/b...d-list.js#L513 and customise the selectRelated action to apply your logic before the records are selected
                    Rabii
                    Web Dev

                    Comment

                    • Firyo
                      Senior Member
                      • Jun 2022
                      • 134

                      #11
                      Originally posted by rabii
                      you can extend this https://github.com/espocrm/espocrm/b...d-list.js#L513 and customise the selectRelated action to apply your logic before the records are selected
                      Ok I see, but where do I say to Espo that I want it only for one specific entity and one specific relation in this entity ?

                      Comment

                      • rabii
                        Active Community Member
                        • Jun 2016
                        • 1250

                        #12
                        you have to create a custom view for the relationship panel in the example above you have to create a custom view for the contacts relationship panel in the clientDefs of the account and you have to extend the relationship.js https://github.com/espocrm/espocrm/b...elationship.js and you can customise the selectRelated and define your logic.
                        Last edited by rabii; 06-15-2023, 09:46 AM.
                        Rabii
                        Web Dev

                        Comment

                        • rabii
                          Active Community Member
                          • Jun 2016
                          • 1250

                          #13
                          Just curious what kind of logic you want to apply beforeRelate / select ? i would assume only logic you would apply here is adding a condition to select (show only certain records to select based on some condition)
                          Rabii
                          Web Dev

                          Comment

                          • Firyo
                            Senior Member
                            • Jun 2022
                            • 134

                            #14
                            Originally posted by rabii
                            Just curious what kind of logic you want to apply beforeRelate / select ? i would assume only logic you would apply here is adding a condition to select (show only certain records to select based on some condition)
                            I want to apply a logic that will eventually display a confirmation modal to the user.

                            Comment

                            • rabii
                              Active Community Member
                              • Jun 2016
                              • 1250

                              #15
                              what do you mean a confirmation modal ? before selecting the records or after selecting record ?
                              Rabii
                              Web Dev

                              Comment

                              Working...