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
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
add a comment |
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
add a comment |
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
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
javascript vue.js vuetify.js
asked Mar 6 at 7:08
SamSam
19714
19714
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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>
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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