Conditionally remove an injected element in a Vue/Element UI dialog

In my Vue project, I am using Element UI to display a modal/dialog with an unsubscribe input form. Upon successful submission of the form, a thank you message is displayed. Everything is working perfectly, except for one issue - I want to remove the close button (the "X" button) that Element UI injects when the success message is shown. Is there a way to achieve this within the injected element?

Vue / Element UI:

<el-dialog :visible.sync="unsubscribeDialogVisible">
    <div class="dialog-content">
        <transition name="fadeIn" mode="out-in">
            <div v-if="unsubscribeInitialState" key="initial" class="dialog-unsubscibe--initial">
                <!-- unsubscribe form -->
                <template>
                    <el-form :model="unsubscribeForm" ref="unsubscribeForm" :rules="unsubscribeRules"
                        class="unsubscribe-form">
                        <el-form-item prop="email" class="form-item--text form-item--input">
                            <el-input placeholder="Email address*" type="email" name="emailUnsubscribe"
                                id="emailUnsubscribe" v-model="unsubscribeForm.email"></el-input>
                        </el-form-item>

                        <button @click.prevent="submitForm('unsubscribeForm')"
                            class="button button--primary button--submit">
                            Submit
                        </button>
                    </el-form>
                </template>
                <!-- end: unsubscribe form -->
            </div>

            <!-- unsubcsribe success -->
            <div v-else key="success" class="dialog-unsubscribe--success">
                <div class="title">
                    <h1 class="title-1 font--primary">
                        <b>You have been successfully unsubscribed</b>
                    </h1>
                </div>
                <!-- /.title -->

                <button @click="closeSuccessMessage()" class="button--submit">
                    Close
                </button>
            </div>
        </transition>
    </div>
</el-dialog>


<script>
    import { Form, FormItem, Input, Dialog } from "element-ui";
    
    export default {
      name: "Unsubscribe",
      components: {
        "el-dialog": Dialog,
        "el-form": Form,
        "el-form-item": FormItem,
        "el-input": Input
      },
      data() {
        const validateEmail = (rule, value, callback) => {
          if (value === "") {
            callback(new Error("Please enter valid email address"));
          } else {
            if (this.unsubscribeForm.email !== "") {
              this.$refs.unsubscribeForm.validateField("email");
            }
            callback();
          }
        };
    
        return {
          unsubscribeDialogVisible: false,
          unsubscribeInitialState: true,
          unsubscribeForm: {
            email: ""
          },
          unsubscribeRules: {
            email: [
              {
                type: "email",
                required: true,
                message: "Please enter email address",
                trigger: ["blur", "change"]
              }
            ]
          }
        };
      },
      methods: {
        showDialog() {
          this.unsubscribeDialogVisible = true;
        },
        submitForm(formName) {
          this.$refs[formName].validate(valid => {
            if (valid) {
              console.log("unsubscribe success");
              this.unsubscribeInitialState = !this.unsubscribeInitialState;
    
              this.$refs[formName].resetFields();
            } else {
              console.log("unsubscribe form submit error");
              return false;
            }
          });
        },
        closeSuccessMessage() {
          this.unsubscribeDialogVisible = false;
          setTimeout(() => {
            this.unsubscribeInitialState = true;
          }, 300);
        },
        resetForm() {
          setTimeout(() => {
            this.$refs.unsubscribeForm.resetFields();
          }, 500);
        }
      },
      mounted() {
        document
          .querySelector(".el-dialog__headerbtn")
          .addEventListener("click", this.resetForm);
      }
    };
    </script>

Answer №1

After reviewing the official documentation, it appears that there is a prop called show-close that can be used with the el-dialog component. You should test passing the same v-if/else condition to this prop:

<el-dialog :visible.sync="unsubscribeDialogVisible" :show-close="unsubscribeInitialState">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Are there any npm packages available for editing PDF files using node.js?

Currently working on a project in node.js app using Bluemix. The task involves receiving a pdf file as a request and then selectively blanking out specific parts of the document. The pdf file will remain constant for all requests, and the areas to be obs ...

Express.js throwing an unexpected 404 error

I'm really struggling to understand why Node (express) only renders the index page and returns a 404 error for other pages, like "comproAffitto" in this example. In my app.js file: var index = require('./routes/index'); var comproAffitto= ...

Organizing lists with HTML unordered lists

Is it possible to sort list items by numbers within a strong tag using JavaScript code? The current code successfully sorts the numbers, but removes them from the div tag. (The JavaScript code used below is for sorting by Name and works properly when &apos ...

PHP-based user interface queue system

I am in the process of developing a website that enables users to manipulate a webcam by moving it from left to right. Each user will have a one-minute window to control the camera. I plan on implementing a queuing system on the site to ensure that users ...

Share on your Twitter feed

Currently seeking assistance in implementing a function on my website that allows users to post their individual posts to Twitter. For example: Message: "hello world" [twitter] By clicking on the twitter button, the message will be posted along with the p ...

Angular Dom does not update when invoking a function within a separate component

Greetings everyone! I am facing a situation where one component (let's name it recipe component) has a reference to another component (named grocery component). The method in my recipe component uses the reference to the grocery component to call a s ...

Generating Dynamic Object Keys following Array Mapping

I have a vision of creating a sophisticated data structure resembling the configuration below: slots: { 'slot_1': { id: 'slot_1', associatedCard: {} }, 'slot_2': { id: 'slot_2& ...

Efficient method for preserving dependent dropdown selections with Select2 and Ajax

I'm currently working on a script that dynamically populates the state dropdown menu based on the selected country id. Everything seems to be functioning correctly, but I've encountered an issue where I can only save the country selection using h ...

Utilize Ajax to transfer an image from an input form to a PHP script

I am currently working on a basic HTML page that includes an image upload form. Here is the code for the form: <input type='file' id='image_uploaded' accept='image'/> <input type='submit' id="upload_image"/ ...

Transforming the unmanaged value state of Select into a controlled one by altering the component

I am currently working on creating an edit form to update data from a database based on its ID. Here is the code snippet I have been using: import React, {FormEvent, useEffect, useState} from "react"; import TextField from "@material ...

Notify of an Invalid CSRF Token within the Action Buttons Present in the Table

I've encountered a problem with the CSRF token when using a Handlebars each loop. I created a data table using the each loop but I'm unable to submit the delete button. The CSRF token only seems to work for submitting new data (POST) and updating ...

Using JQuery to create interactive dropdown menus with dynamic options

I am exploring the possibility of dynamically updating the choices available in an HTML dropdown menu based on the selection made by a user - consider this sample JSON data: series: [ {name: 'Company X', product: 'X1'}, {name: 'Co ...

What is the procedure for incorporating JavaScript into my tic-tac-toe game's HTML and CSS?

I have created a simple Tic Tac Toe game using HTML and CSS. Although there is no embedded Javascript, I do reference a Javascript file for functionality. Can anyone provide me with the most straightforward Javascript code that will display an 'X&apos ...

Is it possible for JavaScript to access and read a local file from a web page hosted locally

I am interested in using html, css, and javascript to develop a user interface for configuring a simulation. This interface will be used to generate a visualization of the simulation and an output parameters file based on multiple input files. It is impor ...

Leveraging External Scripts with Vue.js and Laravel: A Comprehensive Guide

I am new to using vue js and laravel mix, and I am facing some confusion. Previously, I manually loaded scripts without compiling them. However, now that I want to integrate vue js into my project, adding the app.js script at the end of my blade template c ...

Learn how to use props in React with the PluralSight tutorial - don't forget to

While working through a React tutorial on PluralSight, I encountered an error that I'm not sure is my mistake or not. The tutorial directed me to the starting point at JS Complete using this URL: As I followed along, the tutorial led me to the follo ...

Error: Unable to locate the module: Vue-Picture-BD-Marker

After successfully building my Vue project on my personal MacBook and running npm build without any issues, I encountered a problem when trying to deploy it on my CentOS server using Jenkins. The build failed with the following log: ERROR in ./node_modules ...

Help needed with using Regex to restrict the number of alphabetical characters allowed

Struggling with configuring RegEx's. Seeking guidance to create a RegEx with the following criteria: Only allow numbers (0-9) Allow a period (.), negative sign (-), plus sign (+), dollar sign ($), and comma (,) Do not permit any alphabetic characte ...

What are the steps for utilizing the map function to merge an array or nested array into a div element?

I'm currently developing a recipe box application and have shared the code pen for it: http://codepen.io/capozzic1/pen/gmpVyr?editors=0110. The code snippet is as follows: class RecipeList extends React.Component { constructor(props) { super(p ...

Disappearing Act: The Vanishing React.js Dialog Component that Lurks

Currently, I am utilizing a Dialog component from Material-UI and, overall, it is functioning correctly. However, there is an issue where if I click away from the Dialog, it disappears as expected, but occasionally it remains in the DOM with an opacity of ...