tailwind toggle component not passing value in form

huangapple go评论62阅读模式
英文:

tailwind toggle component not passing value in form

问题

我正在尝试在我的表单中(laravel 9中的blade模板)添加一个切换开关。我从https://flowbite.com/docs/forms/toggle/获取了切换开关,但缺少'name'属性,所以我自己添加了,现在它出现在表单数据中,但始终为null。

这是代码:

<label class="relative inline-flex items-center cursor-pointer">
    <input type="checkbox" name="goal" value="" class="sr-only peer">
    <div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600"></div>
    <span class="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300">Goal</span>
</label>

切换开关似乎实际上并未改变复选框的值,但基于'peer'的div表明它是这样的。

我肯定是漏掉了一些非常明显的东西。有任何想法吗?

英文:

I'm trying to add a toggle switch to my form (blade template in laravel 9). I pulled the toggle from https://flowbite.com/docs/forms/toggle/, but it was missing the 'name' attribute so I added that myself, and it now appears in the form data, but it's always null.

Here's the code:

&lt;label class=&quot;relative inline-flex items-center cursor-pointer&quot;&gt;
    &lt;input type=&quot;checkbox&quot; name=&quot;goal&quot; value=&quot;&quot; class=&quot;sr-only peer&quot;&gt;
    &lt;div class=&quot;w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[&#39;&#39;] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all dark:border-gray-600 peer-checked:bg-blue-600&quot;&gt;&lt;/div&gt;
    &lt;span class=&quot;ml-3 text-sm font-medium text-gray-900 dark:text-gray-300&quot;&gt;Goal&lt;/span&gt;
&lt;/label&gt;

As far as I can tell, the toggle switch doesn't actually change the value of the checkbox at all, but the div set to change based on 'peer' suggests that it is.

I must be missing something really obvious. Any ideas?

答案1

得分: 0

你可以删除这个尴尬的问题吗?我好久没有使用复选框了,我忘记了它们是如何工作的。我需要添加在切换开关时传回的值。

英文:

Can I delete this embarrassing question somehow? It's been so long since I used a checkbox, I forgot how they work. I needed to add the value which is passed back when the toggle is switched.

&lt;input type=&quot;checkbox&quot; name=&quot;goal&quot; value=&quot;goal&quot; class=&quot;sr-only peer&quot;&gt;

huangapple
  • 本文由 发表于 2023年5月15日 06:51:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76249990.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定