M
M
Maxim2021-12-17 17:09:21
Vue.js
Maxim, 2021-12-17 17:09:21

How to make it so that when you click on Cancle, the value is not saved, but saved on save?

How to make it so that when you click on Cancle, the value entered in the textarea is not saved, but saved on save?

<template lang="pug">
.modal-task(:style="{display: showDetailsModal}")
    .modal-task-details
        .task
            .name(v-show="show")
                |Name: {{updatedTask.name}}
            .text(v-show="!show")
                textarea(v-model='updatedTask.name')
            .status
                |Status: {{updatedTask.status}}
            .deadline
                |Deadline: {{updatedTask.time}}
            .description(v-show="show")
              |description: {{updatedTask.description1}}
            .text(v-show="!show" @change="handleChange")
                textarea(v-model='updatedTask.description1')
        button(class='add-task' v-on:click="show=!show" v-show="show") Edit
        button(class='add-task' v-on:click="show=!show" v-show="!show" @click="closeForm()") Close
        button(class='add-task' v-show="showSaveButton" @click="saveTask(task)") Save
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { emitter } from '../main'

export default defineComponent({
  name: 'task-details-modal',
  props: ['showDetailsModal', 'task'],
  data () {
    return {
      show: true,
      showSaveButton: true,
      updatedTask: {
        name: '',
        description1: '',
        time: '',
        status: ''
      }
    }
  },
  methods: {
    closeForm () {
      emitter.emit('close', this.task)
      // console.log(this.updatedTask)
    },
    saveTask () {
      emitter.emit('save', this.updatedTask)
    },
    handleChange () {
      this.showSaveButton = true
    }
  },
  created () {
    this.updatedTask = JSON.parse(JSON.stringify(this.task))
  }
})
</script>

And how can I refer to this particular task in the parent component?
mounted () {
    emitter.on('close', task => {
      this.tasks[*indexOfClosedTask*] = task as TaskInterface
      this.showDetailsModal = 'none'
    })
    emitter.on('save', task => {
      this.tasks[*indexOfSavedTask*] = task as TaskInterface
      this.showDetailsModal = 'none'
    })
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question