2017-03-07 1 views
0

私はvue.js 2.0プロジェクトで作業しています。 Vee-Validateプラグインを使用しています。私はフォームを持っており、それが提出されると、それは私のAPIにajaxコールを行います。 api呼び出しが正常に戻ると、同じ形式の別のユーザーを招待できるようにvee検証をクリアしようとしていますが、全く機能していません。Vue.js 2.0 Vee ajax呼び出し後にプラグインがエラーをクリアしないことを確認します

そのdocumentation

で提案されているように、私はそれはまだ私も多分そのあまりにも速く起こっていることを考えているので、私は数秒のために、設定されたタイムアウト機能を追加しましたが、()メソッドのthis.errors.clearを試してみましたエラーをクリアしません。ここで

は、関連するすべてのコードと私のVueのファイルです:

<template> 
    <div v-if="user.first_time_login == 0 && user.stripe_check == 1"> 
    <div class="viv-modal-overlay"> 
     <div class="container"> 
     <div class="viv-modal green"> 
      <span class="modal-title" id="setup-team-top">Now let’s set up your team.</span> 
      <p>Your plan allows up to {{this.user.company.max_users}} users. Would you like to shoot out some team invites before we send you to the dashboard?</p> 
      <div class="invited-users" v-bind:class="{ show: show_invites }" v-if="show_invites"> 
      <p>You can invite up to 4 more team members. <a href="#">Upgrade to add more.</a></p> 
      <ul> 
       <li v-for="invite in invites"> 
       <img src="/img/icons/checkmark.svg" width="20" height="20" alt="success"> 
       You invited {{invite.email}}. 
       <span class="clearfix"></span> 
       </li> 
      </ul> 
      <div class="team-done-adding"> 
       <a href="#">I'm done adding team members.</a> 
      </div> 
      </div> 
      <div class="modal-form"> 
      <form id="setup-stripe-form"> 
       <div class="row"> 
       <div class="col-md-12"> 
        <div class="form-group"> 
        <label>Team Member's Email<span>*</span></label> 
        <input type="text" name="email" v-model="newUser.email" v-validate data-vv-rules="required" class="form-control" :placeholder="'[email protected]'+user.company.company_name.replace(/[^A-Z0-9]+/ig, '').toLowerCase()+'.com'"> 
        <span v-show="errors.has('email')" class="error">{{ errors.first('email') }}</span> 
        </div> 
        <div class="form-group"> 
        <label>Access to Leads and Contacts<span>*</span></label> 
        <select name="access_leads" v-model="newUser.access_leads" v-validate data-vv-rules="required" class="form-control"> 
         <option value="1">they can see leads and contacts they created</option> 
         <option value="2">they can see all leads and contacts</option> 
         <option value="0">no access to leads and contacts</option> 
        </select> 
        <span v-show="errors.has('access_leads')" class="error">{{ errors.first('access_leads') }}</span> 
        </div> 
        <div class="form-group"> 
        <label>Access to Proposals<span>*</span></label> 
        <select name="access_proposals" v-model="newUser.access_proposals" v-validate data-vv-rules="required" class="form-control"> 
         <option value="1">they can see proposals they created</option> 
         <option value="2">they can see all proposals</option> 
         <option value="0">no access to proposals</option> 
        </select> 
        <span v-show="errors.has('access_proposals')" class="error">{{ errors.first('access_proposals') }}</span> 
        </div> 
        <div class="form-group"> 
        <label>Access to Invoices<span>*</span></label> 
        <select name="access_invoices" v-model="newUser.access_invoices" v-validate data-vv-rules="required" class="form-control"> 
         <option value="1">they can see invoices they created</option> 
         <option value="2">they can see all invoices</option> 
         <option value="0">no access to invoices</option> 
        </select> 
        <span v-show="errors.has('access_invoices')" class="error">{{ errors.first('access_invoices') }}</span> 
        </div> 
        <div class="form-group"> 
        <label>Access to Projects<span>*</span></label> 
        <select name="access_projects" v-model="newUser.access_projects" v-validate data-vv-rules="required" class="form-control"> 
         <option value="1">they can see projects they created</option> 
         <option value="2">they can see all projects</option> 
         <option value="0">no access to projects</option> 
        </select> 
        <span v-show="errors.has('access_projects')" class="error">{{ errors.first('access_projects') }}</span> 
        </div> 
       </div> 
       <div class="col-md-12 text-center"> 
        <div class="modal-btn-pad"> 
        <button type="submit" v-bind:class="{ disabled: adding_team_member }" class="btn btn-lg btn-green" @click="submitInviteForm"> 
         <span class="sending-invite" v-if="adding_team_member">Sending Invite <img src="/img/preloader.svg" width="20" height="20"></span> 
         <span v-else>Continue</span> 
        </button><br> 
        <a class="light-link" href="#" @click="skipInviteForm">Skip this for now.</a> 
        </div> 
       </div> 
       </div> 
      </form> 
      </div> 
     </div> 
     </div> 
    </div> 
    </div> 
</template> 

<script> 
import { mapState } from 'vuex' 
export default { 
    data() { 
    return { 
     newUser: { 
     email: '', 
     access_leads: 1, 
     access_proposals: 1, 
     access_invoices: 1, 
     access_projects: 1 
     }, 
     users_invited: 0, 
     invites: [], 
     show_invites: false, 
     adding_team_member: false 
    } 
    }, 
    computed: mapState({ 
    appLoading: state => state.appLoading, 
    user: state => state.user 
    }), 
    methods: { 
    submitInviteForm: function(e) { 

     e.preventDefault() 

     this.$validator.validateAll() 

     if (!this.errors.any()) { 
     //There are no errors, move forward... 

     //Add the team member to the database... 

     //Grab the authorized user 
     const authUser = JSON.parse(window.localStorage.getItem('authUser')) 

     //Create the payload... 
     var newTeamMember = this.newUser 

     //Were adding a team member now so show the loader! 
     this.adding_team_member = true 

     //Create the new company and add the owner... 
     this.$http.post('/api/team', 
     { 
      newTeamMember: JSON.stringify(newTeamMember) 
     }, 
     { 
      headers: { 
      Authorization: 'Bearer ' + authUser.access_token 
      } 
     }).then((response) => { 
      if(response.status === 200) { 
      //Assign the user to a variable 
      var invitedUser = response.body 

      //Add the user to the list of invited users 
      this.invites.push({email: invitedUser.email }) 

      //Show the invite list... 
      this.show_invites = true 

      //Jump to top 
      location.hash = '#setup-team-top' 

      //reset the new user 
      this.newUser.email = '' 
      this.newUser.access_leads = 1 
      this.newUser.access_proposals = 1 
      this.newUser.access_invoices = 1 
      this.newUser.access_projects = 1 

      //Were done adding a team member so hide the loader! 
      this.adding_team_member = false 

      //Clear the validation errors 
      this.errors.clear() 

      } 
     }).catch(function(error){ 
      console.log(error); 
     }) 

     } 
    }, 
    skipInviteForm: function(e) { 
     e.preventDefault() 
     alert('skip invite!') 
    } 
    } 
} 
</script> 

答えて

-1

このissueから抽出されたこのfiddleを見ているようにしてください。 フォームの入力フィールドをリセットした後、基本的にに電話する必要があります。

関連する問題