Announcement

Collapse
No announcement yet.

How to listenTo beforeRelate

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:	269
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:	168
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.​​

  • #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.

    Comment


    • #3
      Originally posted by rabii View Post
      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


      • #4
        i think since version 7.4

        Comment


        • #5
          Originally posted by rabii View Post
          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


          • #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.

            Comment


            • #7
              Originally posted by rabii View Post
              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


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

                Comment


                • #9
                  Originally posted by rabii View Post
                  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


                  • #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

                    Comment


                    • #11
                      Originally posted by rabii View Post
                      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


                      • #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.

                        Comment


                        • #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)

                          Comment


                          • #14
                            Originally posted by rabii View Post
                            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


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

                              Comment

                              Working...
                              X