Skip to content

Instantly share code, notes, and snippets.

@jensgro
Last active October 8, 2019 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jensgro/ddca09e6f6c37a62737a42de9a2db9b0 to your computer and use it in GitHub Desktop.
Save jensgro/ddca09e6f6c37a62737a42de9a2db9b0 to your computer and use it in GitHub Desktop.
Vue-Test - Dingsdays
<div id="app">
<form>
<label for="email">Email-Adresse</label>
<input type="email" required name="email" id="email" @keyup="validate" />
<button id="submit" :disabled="disabled">Abschicken!</button>
</form>
</div>
const app = new Vue({
el: "#app",
data: {
email: "",
disabled: true,
buttonText: "mehr lesen"
},
methods: {
validate(event) {
const input = event.target;
const validity = input.validity;
this.disabled = !validity.valid && !validity.valueMissing;
}
}
});
// jQuery
/*
$(() => {
const $submit = $('#submit');
const $email = $('#email');
$email.keyup(() => {
$submit.prop(
'disabled',
$email.val().length === 0 ||
!$email.prop('validity').valid
);
})
});
*/
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
body {padding: 40px;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment