Created
May 11, 2020 14:17
-
-
Save swanson/d6eb4f80b071538564a615f22882be3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
<div data-controller="required-field" data-required-field-message="Email is required"> | |
<input name="email" data-target="required-field.field" ...> | |
</div> | |
<div data-controller="required-field" data-required-field-message="Password is required"> | |
<input name="password" data-target="required-field.field"> | |
</div> | |
// | |
import { Controller } from "stimulus" | |
export default class extends Controller { | |
static targets = [ "field" ] | |
validate() { | |
if (this.fieldTarget.value.length < 1) { | |
this.element.appendChild(`<p class='warning'>${this.data.get("message")}</p>` | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment