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

    [Solved] How to update form field value dynamically when back from a dialog

    Framework
    3
    14
    3187
    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.
    • S
      Stanley last edited by Stanley

      I write a customized component (based Q-Modal), this is a search help dialog that return the different value according by user input. The code like this
      <template>
      <q-modal v-model=“layoutModal”>
      <q-btn @click=“onShlpPickup()” icon=“done” label=“OK” />

      <script>
      export default {
      props: {
      layoutModal: Boolean,
      fieldName: String
      },
      methods: {
      onShlpPickup () {
      this.$emit(‘callBack’, { retValue: this.returnValue)
      }

      Now go to the main screen.
      <template>
      <form>
      <q-input v-model=“f1” :after="[{icon: ‘search’, handler () { searchHelp(‘f1’) }}]"/>
      <q-input v-model=“f2” :after="[{icon: ‘search’, handler () { searchHelp(‘f2’) }}]"/>
      </form>
      <search-help :layoutModal=“layoutModal” :fieldName=“fieldName” @callBack=“onCallBack”/>

      <script>
      import SearchHelp from ‘components/search-help’
      export default {
      data () {
      return {
      f1,
      f2,
      layoutModal: false,
      fieldName: ‘’
      }
      },
      methods: {
      searchHelp (fieldName) {
      this.layoutModal = true
      this.fieldName = fieldName
      },
      onCallBack (payLoad) {
      this.layoutModal = false
      console.log(payLoad.retValue)
      // question here? How to update field value “f1, f2” dynamically according by which component user has clicked
      }

      1 Reply Last reply Reply Quote 0
      • C
        chbarr last edited by chbarr

        this.$emit(‘callBack’, { fieldName: this.fieldName, retValue: this.retValue }) in onShlpPickup ()

        and

        this[payLoad.fieldName] = payLoad.retValue in onCallBack (payLoad)

        S 2 Replies Last reply Reply Quote 0
        • S
          Stanley last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • S
            Stanley @chbarr last edited by

            @chbarr Thank you!
            The value is updated but the value on the screen is not refreshed.
            Do you know how to solve it?

            1 Reply Last reply Reply Quote 0
            • S
              Stanley @chbarr last edited by Stanley

              @chbarr one thing inform to you, this issue only occurs in nested structure.
              for example: this[student.header.firstName]
              Could you please help check it, thanks!

              1 Reply Last reply Reply Quote 0
              • C
                chbarr last edited by

                i think if fieldName is a nested structure, it’s a little bit complicated.

                onCallBack (payLoad) {
                  let fieldToUpdate = this
                  for (let subfield in payload.fieldName.split('.')) {
                    fieldToUpdate = this.subfield
                  }
                  this[fieldToUpdate] = payLoad.retValue
                }
                
                S 1 Reply Last reply Reply Quote 0
                • S
                  Stanley @chbarr last edited by

                  @chbarr Thanks! But it still does not work. The variable subfield in each call are like 0, 1, 2.
                  The value on the screen still does not refresh. Could you please have a look again, thanks!

                  1 Reply Last reply Reply Quote 0
                  • C
                    chbarr last edited by

                    This post is deleted!
                    1 Reply Last reply Reply Quote 0
                    • C
                      chbarr last edited by chbarr

                      typo in my answer, it’s:
                      for (let subfield of payload.fieldName.split(’.’))

                      S 1 Reply Last reply Reply Quote 0
                      • S
                        Stanley @chbarr last edited by

                        @chbarr Yes, I changed like that. It can get the field name now. But it seems the value “this.subfield” is undefined. Could you please have a look again, thanks!

                        1 Reply Last reply Reply Quote 0
                        • C
                          chbarr last edited by chbarr

                          sorry another typo:

                          onCallBack (payLoad) {
                            let fieldToUpdate = this
                            for (let subfield of payload.fieldName.split('.')) {
                              fieldToUpdate = this[subfield]
                            }
                            fieldToUpdate = payLoad.retValue
                          }
                          
                          S 1 Reply Last reply Reply Quote 0
                          • P
                            phato777 last edited by phato777

                            Perhaps this:
                            https://vuejs.org/v2/api/#Vue-set

                            If it’s a nested object, you have to use set in order for Vue to react visually to the change.

                            More info on Vue reactivity:
                            https://vuejs.org/v2/guide/reactivity.html

                            S 1 Reply Last reply Reply Quote 0
                            • S
                              Stanley @phato777 last edited by

                              @phato777 thanks a lot! it works now.

                              1 Reply Last reply Reply Quote 0
                              • S
                                Stanley @chbarr last edited by

                                @chbarr I know you purpose but it still does not works until using Vue.set. Anyway thanks a lot for help.

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