How to disabled a button based on child component form validation in vue2019 Community Moderator ElectionHow to validate an email address in JavaScript?How can I know which radio button is selected via jQuery?How to prevent buttons from submitting formsjQuery disable/enable submit buttonHow does Facebook disable the browser's integrated Developer Tools?How to bind components with vue js?Angular 2 : Validate child component form fields from the parent componentReset form of child component from parent componentEnable/disable this.props.children inside Child component based on item clickedvue large form with multiple components

Does "Until when" sound natural for native speakers?

Makefile strange variable substitution

Do f-stop and exposure time perfectly cancel?

Can one live in the U.S. and not use a credit card?

Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?

Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?

When a wind turbine does not produce enough electricity how does the power company compensate for the loss?

How to draw cubes in a 3 dimensional plane

Declaring and defining template, and specialising them

Why does Captain Marvel assume the people on this planet know this?

List elements digit difference sort

Is it work or heat?

Why would one plane in this picture not have gear down yet?

Intuition behind counterexample of Euler's sum of powers conjecture

How strictly should I take "Candidates must be local"?

How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?

Linux Ubuntu 18.04 Full Backup

Could you please stop shuffling the deck and play already?

What is the magic ball of every day?

How can I ensure my trip to the UK will not have to be cancelled because of Brexit?

finite abelian groups tensor product.

Child Theme Path Being Ignored With wp_enqueue_scripts

At what distance can a bugbear, holding a reach weapon, with Polearm Mastery, get their Opportunity Attack?

PTIJ: Should I kill my computer after installing software?



How to disabled a button based on child component form validation in vue



2019 Community Moderator ElectionHow to validate an email address in JavaScript?How can I know which radio button is selected via jQuery?How to prevent buttons from submitting formsjQuery disable/enable submit buttonHow does Facebook disable the browser's integrated Developer Tools?How to bind components with vue js?Angular 2 : Validate child component form fields from the parent componentReset form of child component from parent componentEnable/disable this.props.children inside Child component based on item clickedvue large form with multiple components










0















I have a child component



<v-form ref="form" v-model="valid" lazy-validation>
<v-select v-model="test" :items="data" :rules="[v => !!v || 'Required']"></v-select>
</v-form>


If i try this.$refs.form.validate() in child component it is validating.



And in parent component, i have a simple button



<v-btn color="primary" @click="save()">save</v-btn>


On clicking on the button i can call the child component method to get the validation status of the child form. It works great.



Now i would like to disable the button, if the child form is not valid. What is the best way to do this?










share|improve this question


























    0















    I have a child component



    <v-form ref="form" v-model="valid" lazy-validation>
    <v-select v-model="test" :items="data" :rules="[v => !!v || 'Required']"></v-select>
    </v-form>


    If i try this.$refs.form.validate() in child component it is validating.



    And in parent component, i have a simple button



    <v-btn color="primary" @click="save()">save</v-btn>


    On clicking on the button i can call the child component method to get the validation status of the child form. It works great.



    Now i would like to disable the button, if the child form is not valid. What is the best way to do this?










    share|improve this question
























      0












      0








      0








      I have a child component



      <v-form ref="form" v-model="valid" lazy-validation>
      <v-select v-model="test" :items="data" :rules="[v => !!v || 'Required']"></v-select>
      </v-form>


      If i try this.$refs.form.validate() in child component it is validating.



      And in parent component, i have a simple button



      <v-btn color="primary" @click="save()">save</v-btn>


      On clicking on the button i can call the child component method to get the validation status of the child form. It works great.



      Now i would like to disable the button, if the child form is not valid. What is the best way to do this?










      share|improve this question














      I have a child component



      <v-form ref="form" v-model="valid" lazy-validation>
      <v-select v-model="test" :items="data" :rules="[v => !!v || 'Required']"></v-select>
      </v-form>


      If i try this.$refs.form.validate() in child component it is validating.



      And in parent component, i have a simple button



      <v-btn color="primary" @click="save()">save</v-btn>


      On clicking on the button i can call the child component method to get the validation status of the child form. It works great.



      Now i would like to disable the button, if the child form is not valid. What is the best way to do this?







      javascript vue.js vuetify.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 at 7:08









      SamSam

      19714




      19714






















          1 Answer
          1






          active

          oldest

          votes


















          0














          The validity of your form is updated live by vuetify, via the v-model property of the v-form. You just need to bind this property such that it's accessible from wherever you need it. When a property like this is used in more than one component, it's shared state. I much prefer getting shared state out of Vue components, and putting it in a global object that I like to call vueStore. There are other ways to share state, but I like this way !






          var vueStore = 
          valid:false

          Vue.component('my-child', 'Required']"></v-select>
          </v-form>`,
          data()
          return items:['','red','green','blue'],
          vueStore:vueStore,
          test:null


          )

          var vm = new Vue(
          el:'#app',
          data:vueStore:vueStore,
          methods:
          save()
          alert("saving...")


          )

          <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.18/vue.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.js"></script>
          <link href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.css" rel="stylesheet"/>
          <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

          <div id="app">
          <v-app>
          <my-child></my-child>
          <v-btn color="primary" @click="save()" :disabled="!vueStore.valid">save</v-btn>
          </v-app>
          </div>








          share|improve this answer

























          • Actually child is not outside of the parent view.

            – Sam
            Mar 6 at 8:57












          • Hi, in the above code where are calling this proxyValidate method from parent? And how it will help to disable button in parent?

            – Sam
            Mar 6 at 15:18











          • Ok this is working now. Is this what you were after? proxyValidate wasn't needed.

            – bbsimonbb
            Mar 6 at 15:30











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55017465%2fhow-to-disabled-a-button-based-on-child-component-form-validation-in-vue%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The validity of your form is updated live by vuetify, via the v-model property of the v-form. You just need to bind this property such that it's accessible from wherever you need it. When a property like this is used in more than one component, it's shared state. I much prefer getting shared state out of Vue components, and putting it in a global object that I like to call vueStore. There are other ways to share state, but I like this way !






          var vueStore = 
          valid:false

          Vue.component('my-child', 'Required']"></v-select>
          </v-form>`,
          data()
          return items:['','red','green','blue'],
          vueStore:vueStore,
          test:null


          )

          var vm = new Vue(
          el:'#app',
          data:vueStore:vueStore,
          methods:
          save()
          alert("saving...")


          )

          <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.18/vue.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.js"></script>
          <link href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.css" rel="stylesheet"/>
          <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

          <div id="app">
          <v-app>
          <my-child></my-child>
          <v-btn color="primary" @click="save()" :disabled="!vueStore.valid">save</v-btn>
          </v-app>
          </div>








          share|improve this answer

























          • Actually child is not outside of the parent view.

            – Sam
            Mar 6 at 8:57












          • Hi, in the above code where are calling this proxyValidate method from parent? And how it will help to disable button in parent?

            – Sam
            Mar 6 at 15:18











          • Ok this is working now. Is this what you were after? proxyValidate wasn't needed.

            – bbsimonbb
            Mar 6 at 15:30
















          0














          The validity of your form is updated live by vuetify, via the v-model property of the v-form. You just need to bind this property such that it's accessible from wherever you need it. When a property like this is used in more than one component, it's shared state. I much prefer getting shared state out of Vue components, and putting it in a global object that I like to call vueStore. There are other ways to share state, but I like this way !






          var vueStore = 
          valid:false

          Vue.component('my-child', 'Required']"></v-select>
          </v-form>`,
          data()
          return items:['','red','green','blue'],
          vueStore:vueStore,
          test:null


          )

          var vm = new Vue(
          el:'#app',
          data:vueStore:vueStore,
          methods:
          save()
          alert("saving...")


          )

          <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.18/vue.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.js"></script>
          <link href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.css" rel="stylesheet"/>
          <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

          <div id="app">
          <v-app>
          <my-child></my-child>
          <v-btn color="primary" @click="save()" :disabled="!vueStore.valid">save</v-btn>
          </v-app>
          </div>








          share|improve this answer

























          • Actually child is not outside of the parent view.

            – Sam
            Mar 6 at 8:57












          • Hi, in the above code where are calling this proxyValidate method from parent? And how it will help to disable button in parent?

            – Sam
            Mar 6 at 15:18











          • Ok this is working now. Is this what you were after? proxyValidate wasn't needed.

            – bbsimonbb
            Mar 6 at 15:30














          0












          0








          0







          The validity of your form is updated live by vuetify, via the v-model property of the v-form. You just need to bind this property such that it's accessible from wherever you need it. When a property like this is used in more than one component, it's shared state. I much prefer getting shared state out of Vue components, and putting it in a global object that I like to call vueStore. There are other ways to share state, but I like this way !






          var vueStore = 
          valid:false

          Vue.component('my-child', 'Required']"></v-select>
          </v-form>`,
          data()
          return items:['','red','green','blue'],
          vueStore:vueStore,
          test:null


          )

          var vm = new Vue(
          el:'#app',
          data:vueStore:vueStore,
          methods:
          save()
          alert("saving...")


          )

          <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.18/vue.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.js"></script>
          <link href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.css" rel="stylesheet"/>
          <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

          <div id="app">
          <v-app>
          <my-child></my-child>
          <v-btn color="primary" @click="save()" :disabled="!vueStore.valid">save</v-btn>
          </v-app>
          </div>








          share|improve this answer















          The validity of your form is updated live by vuetify, via the v-model property of the v-form. You just need to bind this property such that it's accessible from wherever you need it. When a property like this is used in more than one component, it's shared state. I much prefer getting shared state out of Vue components, and putting it in a global object that I like to call vueStore. There are other ways to share state, but I like this way !






          var vueStore = 
          valid:false

          Vue.component('my-child', 'Required']"></v-select>
          </v-form>`,
          data()
          return items:['','red','green','blue'],
          vueStore:vueStore,
          test:null


          )

          var vm = new Vue(
          el:'#app',
          data:vueStore:vueStore,
          methods:
          save()
          alert("saving...")


          )

          <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.18/vue.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.js"></script>
          <link href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.css" rel="stylesheet"/>
          <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

          <div id="app">
          <v-app>
          <my-child></my-child>
          <v-btn color="primary" @click="save()" :disabled="!vueStore.valid">save</v-btn>
          </v-app>
          </div>








          var vueStore = 
          valid:false

          Vue.component('my-child', 'Required']"></v-select>
          </v-form>`,
          data()
          return items:['','red','green','blue'],
          vueStore:vueStore,
          test:null


          )

          var vm = new Vue(
          el:'#app',
          data:vueStore:vueStore,
          methods:
          save()
          alert("saving...")


          )

          <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.18/vue.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.js"></script>
          <link href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.css" rel="stylesheet"/>
          <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

          <div id="app">
          <v-app>
          <my-child></my-child>
          <v-btn color="primary" @click="save()" :disabled="!vueStore.valid">save</v-btn>
          </v-app>
          </div>





          var vueStore = 
          valid:false

          Vue.component('my-child', 'Required']"></v-select>
          </v-form>`,
          data()
          return items:['','red','green','blue'],
          vueStore:vueStore,
          test:null


          )

          var vm = new Vue(
          el:'#app',
          data:vueStore:vueStore,
          methods:
          save()
          alert("saving...")


          )

          <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.18/vue.js"></script>
          <script src="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.js"></script>
          <link href="https://cdnjs.cloudflare.com/ajax/libs/vuetify/1.5.5/vuetify.min.css" rel="stylesheet"/>
          <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

          <div id="app">
          <v-app>
          <my-child></my-child>
          <v-btn color="primary" @click="save()" :disabled="!vueStore.valid">save</v-btn>
          </v-app>
          </div>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 6 at 15:34

























          answered Mar 6 at 8:24









          bbsimonbbbbsimonbb

          10.3k63447




          10.3k63447












          • Actually child is not outside of the parent view.

            – Sam
            Mar 6 at 8:57












          • Hi, in the above code where are calling this proxyValidate method from parent? And how it will help to disable button in parent?

            – Sam
            Mar 6 at 15:18











          • Ok this is working now. Is this what you were after? proxyValidate wasn't needed.

            – bbsimonbb
            Mar 6 at 15:30


















          • Actually child is not outside of the parent view.

            – Sam
            Mar 6 at 8:57












          • Hi, in the above code where are calling this proxyValidate method from parent? And how it will help to disable button in parent?

            – Sam
            Mar 6 at 15:18











          • Ok this is working now. Is this what you were after? proxyValidate wasn't needed.

            – bbsimonbb
            Mar 6 at 15:30

















          Actually child is not outside of the parent view.

          – Sam
          Mar 6 at 8:57






          Actually child is not outside of the parent view.

          – Sam
          Mar 6 at 8:57














          Hi, in the above code where are calling this proxyValidate method from parent? And how it will help to disable button in parent?

          – Sam
          Mar 6 at 15:18





          Hi, in the above code where are calling this proxyValidate method from parent? And how it will help to disable button in parent?

          – Sam
          Mar 6 at 15:18













          Ok this is working now. Is this what you were after? proxyValidate wasn't needed.

          – bbsimonbb
          Mar 6 at 15:30






          Ok this is working now. Is this what you were after? proxyValidate wasn't needed.

          – bbsimonbb
          Mar 6 at 15:30




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55017465%2fhow-to-disabled-a-button-based-on-child-component-form-validation-in-vue%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved