You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What would you like to be able to do? Can you provide some examples?
I use Field-nested-has_many a lot. And this time in order to make the experience better when rendering fields within a nested has many way.
For instance My page is a 'Period' and this Object has been build through a callBack after user creation. i have something like this
So the Period is build through a callback.
Then when the user want to fill out the Period form, in fact it's an edit view.
So there are some fields that it's not necessary to display.
As we can see Period object has already some set attributes like weekly:false, yearly:true.
These attributes should alow me to display only fields that matter to display for a 'period yearly:true'.
I would like to hide inside form some fields base on the page attribute already existing .
So the objective is to pass the page object to the a Field-nested-has_many.
#<Administrate::Page::Form:0x00007ff4c258ade0>
Basically as the gem is designed right now, it's seams to be not possible to pass any page params object to the final field like I did initially through the render
send page parameter to the final field
inside the gem administrate-field-nested_has_many inside #views/fields/nested_has_many/_fields.html.erb
<divclass="nested-fields nested-fields_<%= field.attribute %>">
<divclass="card light-shadow">
<divclass="card-body">
<% field.nested_fields_for_builder(f).eachdo |attribute| -%> <div class="form-group field-unit field-unit--<%= attribute.html_class %>">
<%= render_fieldattribute,f: f,page: page%> # 👈🏽 I need that page object in within a field
</div>
<% end -%> <%# some code%>
</div> </div>
</div>
then we have ActionView::Template::Error => undefined local variable or method `page' for ...
and that normal cause page is not defined yet.
How could we go about implementing that?
I founded a way to do this but it's kinda not very safe I think. inside #app/views/admin/period/_form.html.erb
at the top of the form i just added that line
<%= @page=page.resource%><%= form_for([namespace, page.resource], html: { class: "form", id: "#{action_name}_#{controller_name.singularize}_#{page.resource.id}" }) do |f| %>
<%# restofthecode%><% end %>
inside the gem administrate-field-nested_has_many inside #views/fields/nested_has_many/_fields.html.erb
inside the gem administrate-field-nested_has_many inside #app/views/fields/nested_has_many/_form.html.erb
I know that it's kinda snaky but here the thing how hide properly fields if we needn't ?
I can put now some logic inside the Gem like
<% if@page.class == Period %>
<% if@page.weekly%> <!-- / page is Period and weekly -->
<% if @page.refund_on_period %> <!-- / page is PeriodPack and weekly and period_refunds --> <% if field.attribute != :period_selected_ranges%> <%= render( partial: "fields/nested_has_many/fieldset", locals: { field: field, f: f }, ) %> <% end %> <% else %> #.... <% end %> <% end %> <!-- / page is Period but not weekly --> <%else %> <% if @page.refund_on_period %> #.... <% else %> #.... <% end %> <% end %><%else %> #....<% end %>
and then inside my final field i can check if the Period is weekly or not before display the field
<%if@page.weekly?%> # the field<%end%>
Can you think of other approaches to the problem?
Maybe rethink the Gem and implement the following approach option and propose a PR for that feature if it's not existing yet at all. Because clearly i do not know if there is an easiest way to suround my objective which is to hide some field when i need to.
=> pass params page to the gem
=> Add some conditions inside hash option.
The text was updated successfully, but these errors were encountered:
v2lrf
changed the title
Issue: Feature Pass Page params to field-nested_has_many - Already possible ?
Issue: Feature or Already possible ? Pass Page params to field-nested_has_many - hide field if not necessary
May 23, 2020
I think that this is not really an issue with this plugin, but rather with Administrate itself, which doesn't give information to each field about their context. Does that sound right?
If this is the case, there isn't a better solution at the moment. We'd have to make some changes to Administrate, but this is slow going. I'm already working on something in that general area (but not the same thing), so any change like this would have to wait, to avoid conflicts and allow for a cleaner upgrade path :-(
I use Field-nested-has_many a lot. And this time in order to make the experience better when rendering fields within a nested has many way.
For instance My page is a 'Period' and this Object has been build through a callBack after user creation. i have something like this
So the Period is build through a callback.
Then when the user want to fill out the Period form, in fact it's an edit view.
So there are some fields that it's not necessary to display.
As we can see Period object has already some set attributes like
weekly:false, yearly:true
.These attributes should alow me to display only fields that matter to display for a 'period yearly:true'.
I would like to hide inside form some fields base on the page attribute already existing .
So the objective is to pass the page object to the a Field-nested-has_many.
#<Administrate::Page::Form:0x00007ff4c258ade0>
Basically as the gem is designed right now, it's seams to be not possible to pass any page params object to the final field like I did initially through the render
send page parameter to the final field
inside the gem administrate-field-nested_has_many inside #views/fields/nested_has_many/_fields.html.erb
receive the page parameter from the gem
inside #app/views/fields/multiple_select_field/_form.html.erb
then we have ActionView::Template::Error => undefined local variable or method `page' for ...
and that normal cause page is not defined yet.
I founded a way to do this but it's kinda not very safe I think.
inside #app/views/admin/period/_form.html.erb
at the top of the form i just added that line
inside the gem administrate-field-nested_has_many inside #views/fields/nested_has_many/_fields.html.erb
inside the gem administrate-field-nested_has_many inside #app/views/fields/nested_has_many/_form.html.erb
I know that it's kinda snaky but here the thing how hide properly fields if we needn't ?
I can put now some logic inside the Gem like
and then inside my final field i can check if the Period is weekly or not before display the field
Maybe rethink the Gem and implement the following approach option and propose a PR for that feature if it's not existing yet at all. Because clearly i do not know if there is an easiest way to suround my objective which is to hide some field when i need to.
=> pass params page to the gem
=> Add some conditions inside hash option.
I guess omething like this
The text was updated successfully, but these errors were encountered: