quasar icon indicating copy to clipboard operation
quasar copied to clipboard

Pass additional arguments to @save event handler of the QPopupEdit

Open sontis3 opened this issue 8 years ago • 6 comments

Hi! I have QPopupEdit that is used to edit a value “in place” a cell in a QTable.

    <q-table  :columns="columns" :visible-columns="visibleColumns" row-key="name" :data="ds">
    .......
      <q-tr slot="body" slot-scope="props" :props="props">
        <q-td v-for="col in props.cols" :key="col.name" :props="props">
    .......
          <template v-else-if="col.classes === 'popup-edit'">
            {{ col.value }}
            <q-popup-edit v-model="props.row[col.field]" @save="UpdateDocument">
            </q-popup-edit>
          </template>
        </q-td>
      </q-tr>
    .......
    </q-table>

After submit QPopupEdit i would like to send request for update the document. For this action i need documentId and some fields, wich stored in row of QTable, but handler UpdateDocument receive only "val" and "initialValue". If I will write <q-popup-edit v-model="props.row[col.field]" @save="UpdateDocument(props.row)"> then i can send update request, but in case of update error can not restore old value of table cell. How pass additional arguments into @save handler? For example @save="UpdateDocument(val, initialValue, props.row) Like problem discussed in https://forum.quasar-framework.org/topic/2725/qpopupedit-how-to-pass-own-argument

sontis3 avatar Nov 09 '18 16:11 sontis3

@sontis3 yep would be nice to do that, solution for now is add a unique ref on your q-popup-edit and pass it as argument in one of its events in your case on-save like so @save="UpdateDocument($event, $ref[myUniqueRef].initialValue, props.row). the $event is the new value, @save="UpdateDocument($ref[myUniqueRef], props.row) instead and process the ref's value / initialValue in the called method. I guess you can file a request for feature about this.

metalsadman avatar Nov 10 '18 03:11 metalsadman

You can use <q-popup-edit :value="props.row[col.field]" @input="val => UpdateDocument(col.field, val)">.

Build further from here.

pdanpdan avatar Nov 12 '18 13:11 pdanpdan

@pdanpdan, thanks. In my case solution is <q-popup-edit :value="props.row[col.field]" @save="(val, initialValue) => UpdateDocument(val, initialValue, props.row)"> Arrow function helped to solve the problem of additional arguments.

sontis3 avatar Nov 12 '18 17:11 sontis3

good to know there are other ways, i don't like ref way much, specially if it's from something out of a loop.

metalsadman avatar Nov 12 '18 17:11 metalsadman

感谢 已解决 神奇的quasar

k0sf avatar Jan 06 '20 16:01 k0sf

Translation: "Thanks resolved magical quasar"

hawkeye64 avatar Jan 06 '20 18:01 hawkeye64