Previews

No matching results.

Pages

No matching results.

x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<form class="card flex flex-col gap" data-controller="form" data-action="change->form#disableSubmitWhenInvalid" action="/lookbook/home/index" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="zAwayTeDy__vrDso1h7ivf6cdsbjVNchv3qPw8Y_ecv-WABULyAfNu2Hx9jJ1mPqvW3TKqksgcV3q_vIqG1KYg" autocomplete="off" />
<div class="flex flex-col">
<h3 class="font-semibold leading-none mbe-1">Create project</h3>
<p class="text-sm text-subtle">Deploy your new project in one-click.</p>
</div>
<div class="flex flex-col gap mb-2">
<div class="flex flex-col gap-half">
<label class="text-sm font-medium leading-none" for="name">Name (required)</label>
<input placeholder="Name of your project" class="input" required="required" type="text" name="name" id="name" />
</div>
<div class="flex flex-col gap-half">
<label class="text-sm font-medium leading-none" for="framework">Framework</label>
<select class="input" name="framework" id="framework"><option value="ruby">Ruby on Rails</option>
<option value="laravel">Laravel</option>
<option value="next">Next</option></select>
</div>
</div>
<div class="flex items-center">
<input type="submit" name="commit" value="Create" class="btn btn--primary" disabled="disabled" data-form-target="submit" data-disable-with="Create" />
</div>
</form>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%= form_with url: nil, class: "card flex flex-col gap", data: { controller: "form", action: "change->form#disableSubmitWhenInvalid" } do |form| %>
<div class="flex flex-col">
<h3 class="font-semibold leading-none mbe-1">Create project</h3>
<p class="text-sm text-subtle">Deploy your new project in one-click.</p>
</div>
<div class="flex flex-col gap mb-2">
<div class="flex flex-col gap-half">
<%= form.label :name, "Name (required)", class: "text-sm font-medium leading-none" %>
<%= form.text_field :name, placeholder: "Name of your project", class: "input", required: true %>
</div>
<div class="flex flex-col gap-half">
<%= form.label :framework, class: "text-sm font-medium leading-none" %>
<%= form.select :framework, [["Ruby on Rails", "ruby"], ["Laravel", "laravel"], ["Next", "next"]], {}, class: "input" %>
</div>
</div>
<div class="flex items-center">
<%= form.submit "Create", class: "btn btn--primary", disabled: true, data: { form_target: "submit" } %>
</div>
<% end %>
CSS is not required or multiple files are needed, check the notes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Controller } from "@hotwired/stimulus"
import debounce from "https://esm.sh/just-debounce-it@3.2.0?standalone"
export default class extends Controller {
static targets = [ "cancel", "submit" ]
initialize() {
this.debouncedSubmit = debounce(this.submit.bind(this), 300)
}
submit({ params: { submitter } }) {
if (submitter) {
this.element.requestSubmit(this.#find(submitter))
} else {
this.element.requestSubmit()
}
}
reset() {
this.element.reset()
}
cancel() {
this.cancelTarget?.click()
}
preventAttachment(event) {
event.preventDefault()
}
disableSubmitWhenInvalid() {
if (this.element.checkValidity()) {
this.submitTarget.removeAttribute("disabled")
} else {
this.submitTarget.toggleAttribute("disabled", true)
}
}
#find(id) {
return document.getElementById(id) || this.#notFound(id)
}
#notFound(id) {
throw new Error(`Submitter with ID "${id}" not found`)
}
}