Enable or Disable Toggle by default when first page load
Hi Everyone i have problem when i create custom function schema on my grid to show list based on checklists that i have
Here's the code, and i got trouble when i want to set by default the toggle is enable/active/on is everyone have any good approach to solve this problem ?
33 Replies
This image is of the create form?
@Ramdani Syaputra
Edited form, and inside repeater
Yea so on the edit form there is no "default" because it checks for record details.
Is there a reason why not just use a relationship repeater?
i did but the result is empty
thats why im using custom schema in that grid
is there any good approach for this ?
Ah, i think i understand what you want to do.
Wouldn't a checkbox list field be better here tho?
Yes its better, but still same, the result are empty if im using relationship, also when im using custom schema its also cannot "checked" by the result of $checklist->check
Thats probably because you haven;'t setup your relations the proper way.
To attach "checklists" to a model, first establish the appropriate relationships. Once that's done, creating a relational field becomes straightforward.
Assuming you have a table named checklists with the columns;
id, name, created_at, updated_at
, you can create a pivot table to connect this table with your model (or use a morph relationship). This approach allows you to use a checkbox list to easily add or remove checklists from your model, eliminating the need to toggle a button.I did already
so basically i have WorkJob model and it has relation to JobReportChecklist model and the relation is HasOne
and also inside JobReportChecklist i have relation to JobChecklist with hasMany relation
And also here my schema repeater the result in grid its just showing the default input and the default toggle not my data in database from checklists relation
So this model you are currently editing has relational results?
Your
$model->jobReportChecklist
returns anything ?Yep this part
I’m sorry, but I’m not quite sure what you’re trying to achieve. 😅 When you set up a relationship with a repeater it should fill the repeater with the records from the relationship (which seems to be what is happening) what is exactly the problem?
I want just to make the button is set to active/enable when first time access edit page, thats it, also its kinda hard to do i already did what you mention before but the result for this checklists its still empty
i did what you mention before, but this is for another section, only checklists section is weird for me
But you are editing a record which has the value on
false
?on true actually
Oke so when you click on edit it says false?
yes, i want the toggle follow the check on my database, when its "1" then on
It should do that already when you edit.
You sure the column name matches?
when i hit the toggle to "on" it did updated on the table, but when i reload, its become "off" again
but the "check" field its still "on(1)"
Yea so its something with your column or relationship.
Try this and see if it works
(Just for testing)
actually the checklists its inside jobReportChecklist
so the parent is jobReportChecklist its showing this data
?
I think you might want to reconsider your approach. As I mentioned, with the right relationship, it can be much easier and should work seamlessly right from the start.
Yes i got your advice, maybe i need to see which part im doing it wrong, and thanks for your help 😄
Isn't this what you are trying to do?
@Ramdani Syaputra
Yes correct i did on this part and its success
So it works?
see this maybe you have idea
thats the problem i currently face in last second video
or is there any approach that we can "force" the toggle to become true/false ?
Again i think its your relational setup.
Okay thanks ill check back my code