英文:
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:
<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>
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.
<input type="checkbox" name="goal" value="goal" class="sr-only peer">
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论