我正在使用 htmx 和 hyperscript,我希望在表單中所有必需的輸入字段都有效時啟用“提交按鈕”(添加用戶)。在這種情況下,必須定義一個非空名稱和一個有效的電子郵件地址。
<form hx-post="/example" hx-target="#table tbody" hx-swap="beforeend">
<label class="control-label" for="nameInput">Name</label>
<input id="nameInput" name="name" class="form-control" type="text" required placeholder="John Doe"/>
<label class="control-label" for="emailInput">Email</label>
<input id="emailInput" name="email" class="form-control" type="email" required placeholder="[email protected]"/>
<button _="<what should I write here??>" class="btn btn-primary" disabled>Add User</button>
</div>
</form>
我應該寫什麼而不是<what should I write here??>
讓這發生?
這樣的事情應該工作:
<button _="on change from closest <form/>
for elt in <[required]/>
if the elt's value is empty
add @disabled then exit
end
end
remove @disabled" class="btn btn-primary" disabled>Add User</button>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句