No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Best way to manage modals forms

    Help
    5
    5
    2852
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      damosse31 last edited by damosse31

      Dear Quasarians !

      In my project I have some forms in q-modal (ex: for user edit profile)

      Actually I manage modals as below:

      Modal that don’t need any return : (ex: Edit User Profile)

      • I create a component modalEditUser.vue who contain a q-modal and all my inputs form inside
      • I declare an open() method inside my modalEditUser.vue
      • From my parent page, I declare the modalEditUser component and I call open() with this.$refs.myComponentRef.open() when I need to open it.
      • Inside component the user is loaded from open() method (I call the user from ajax API)
      • When the modal is validated, I check for fields validation and post on API then I close the modal (this.$refs.xxxx.close())

      Modal that need to return an object to parent : (ex: an Invoice item return to Invoice parent)

      • I create a component modalEditItem.vue who contain a q-modal and all my inputs form to edit the item (price, ref, VAT etc…)
      • I declare an open() method who contain an item object in parameter : open(item)
      • I declare props OnReturnItem who is function and return the edited item if the modal is validated
      • From my Invoice parent, I declare the modal component and I call it with open(itemToEdit)
      • When user click to the Save button in modal, the modal close and call OnReturnItem function
      • In this case, I can use OnReturnItem from parent page (Invoice) to manage my edited item from modal (ex: add it in items array etc…)

      I think there is a better solutions to manage modals from parent but… yeah, that is the question 😊 What do you think about ?

      Regards
      Dams

      1 Reply Last reply Reply Quote 0
      • benoitranque
        benoitranque last edited by

        It depends what you mean by better way… If you mean you have a lot of modals and it is getting messy, use subroutes. You can add props and event listeners on your router-view

        1 Reply Last reply Reply Quote 0
        • s.molinari
          s.molinari last edited by

          Dear Quasarers !

          Hehe…maybe Quasarians sounds better? 😄

          Scott

          1 Reply Last reply Reply Quote 1
          • rstoenescu
            rstoenescu Admin last edited by

            Hi, like Benoit said, better use sub-routes. Any specific reason to use Modals? Also, have you thought about using Vuex for state management? http://quasar-framework.org/guide/components-sharing-state.html

            1 Reply Last reply Reply Quote 0
            • A
              afd last edited by

              Another way: you could treat the whole modal as an input. Pass a v-model to the modal and follow the protocol to signal its change (this.emit('input', value)), see the vue.js section on custom inputs

              1 Reply Last reply Reply Quote 0
              • First post
                Last post