Home > Net >  how can check two condition simultaneity in vue js
how can check two condition simultaneity in vue js

Time:04-07

I am trying to check if attachment exist in request and attachment field not exist in form it show message in modal and same if body text exist in request and rich text field not exist in form it show error,

but in my case if attachment exist in request and attachment field is exist exist it continue and move to else if but rich text field not exist in form and it not show error because it not execute the if inside the if. I don't know how can i check both condition.

 if (this.selectedForm) {
    let attachmentField = this.selectedForm.formFields.filter(formField => {
      return formField.fieldAttributeType == 'attachment'
    })
    let descriptionField = this.selectedForm.formFields.filter(formField =>{
      return formField.fieldAttributeType == 'rich_text'
    })
    debugger
    if (this.request.attachments.length > 0 && attachmentField.length == 0) {
      debugger
      this.missingFields.push("Attachment field does't exist in custom form");
      if (this.request.bodyText.length > 0 && descriptionField.length == 0) {
        this.missingFields.push("and Rich_text field does't exist in custom form");
      }
      this.$refs.ticketCreationConfirmation.open();
    } else if (this.missingFields.length == 0){
      this.addRequest(this.request);     
    }
  }

CodePudding user response:

if (this.selectedForm) {
    let attachmentField = this.selectedForm.formFields.filter(formField => {
        return formField.fieldAttributeType == 'attachment'
    })

    let descriptionField = this.selectedForm.formFields.filter(formField => {
        return formField.fieldAttributeType == 'rich_text'
    })

    if (this.request.attachments.length > 0 && attachmentField.length == 0) {
        this.missingFields.push("Attachment field doesn't exist in custom form");
    }

    if (this.request.bodyText.length > 0 && descriptionField.length == 0) {
        this.missingFields.push("Rich_text field doesn't exist in custom form");
    }

    if (this.missingFields.length > 0) {
        this.$refs.ticketCreationConfirmation.open();
    } else {
        this.addRequest(this.request);     
    }
  }

You can then join the error messages like that if you want to display them joined with "and":

this.missingFields.join(" and ");
  • Related