[英]toggle button coded with javascript in blade file cannot save status in database
[英]I am trying to create a toggle button that turns on or off a person's availability status and update the current status in database
现在这就是我所拥有的,它正在切换,但 boolean 值在数据库中没有改变
<input type="checkbox" name="availability" id="toggle-one">
我有这个脚本控制切换
<script>
$(function() {
$('#toggle-one').bootstrapToggle({
on: 'Available',
off: 'Not Available'
});
})
这是模式中的字段
availability:{
type:Boolean,
default:false
},
没有帮助太小,我只需要有人指出我正确的方向,谢谢
您需要监听事件并根据其 state 像这样分配真或假
$(function() {
$('#toggle-on').change(function() {
console.log($(this).prop('checked'));
//in schema that you are sending to server assign value of $(this).prop('checked')
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.