-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Don't allow a subcategory to be assigned to another subcategory to ensure 1 level of nesting max #1730
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, agree with the strategy here!
<%= f.select :parent_id, categories.pluck(:name, :id), { include_blank: "(unassigned)", label: "Parent category (optional)" }, disabled: category.parent? %> | ||
<% if category.parent? %> | ||
<span class="text-xs italic pl-2 text-gray-500">This category couldn’t be assigned as a subcategory because it already has subcategories.</span> | ||
<% end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here, we can just have a conditional:
<% unless category.parent? %>
<%= f.select :parent_id ...
<% end %>
That way, if the user is not allowed to assign a parent, we don't ever give them the option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, i agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good now. Left one more comment to address, then I think we're good to merge!
app/views/categories/_form.html.erb
Outdated
@@ -1,46 +1,49 @@ | |||
<%# locals: (category:, categories:) %> | |||
<%= turbo_frame_tag 'form' do %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? What was the purpose of adding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh, i forgot to remove this... it's done in 2c07cd6. ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Nice work, thanks for the fix.
Fixes issue #1677