Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow destroying nested attributes #184

Merged
merged 1 commit into from
Nov 26, 2024
Merged

Conversation

mjgiarlo
Copy link
Member

@mjgiarlo mjgiarlo commented Nov 26, 2024

Fixes #183

Screenshot from 2024-11-25 15-55-55

@@ -20,7 +20,7 @@ def call
type: 'button',
**options
) do
label
label || content
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow button component to have content injected. Allows us to style a button as a bootstrap icon, such as for deleting nested forms.

Comment on lines +26 to +29
def validate_options!(options)
opts = { allow_destroy: true }.merge(options)
opts.assert_valid_keys(:allow_destroy)
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow developers to toss the allow_destroy arg at nested attributes and no-op. Raise an exception if any other options passed.

In practice, the nested attrs implementation in H3 allows all nested attributes to be destroyed.

@mjgiarlo mjgiarlo force-pushed the destroyable-related-links#183 branch from 278d25f to 0f8c00f Compare November 26, 2024 00:15
Comment on lines +1 to +2
<%= render Elements::Forms::TextFieldComponent.new(field_name: :text, label: I18n.t('related_links.edit.fields.text.label'), form:) %>
<%= render Elements::Forms::TextFieldComponent.new(field_name: :url, label: I18n.t('related_links.edit.fields.url.label'), form:) %>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Divorce the related links i18n from works, since we will use them as part of collections with the same labels.

@mjgiarlo mjgiarlo force-pushed the destroyable-related-links#183 branch from 0f8c00f to 1b03b04 Compare November 26, 2024 00:33
Comment on lines +75 to +84
fill_in('Link text', with: 'delete')
fill_in('URL', with: 'me')
# Test adding a new nested field
click_link_or_button('+ Add another related link')
fill_in('work_related_links_attributes_1_text', with: updated_related_links.first['text'])
fill_in('work_related_links_attributes_1_url', with: updated_related_links.first['url'])
# Test removing a nested field
within('div[data-index="0"]') do
find('button[data-action="click->nested-form#delete"]').click
end
Copy link
Member Author

@mjgiarlo mjgiarlo Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's how I'm testing adding and removing nested fields, but note that there's a bit of false confidence because this system spec needs work per this still-top-of-ready issue: #138

Copy link
Contributor

@justinlittman justinlittman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve pending handling comment.

@mjgiarlo mjgiarlo force-pushed the destroyable-related-links#183 branch from 1b03b04 to b9d690e Compare November 26, 2024 16:55
@mjgiarlo mjgiarlo requested review from justinlittman and removed request for justinlittman November 26, 2024 16:56
@mjgiarlo mjgiarlo merged commit 894afb0 into main Nov 26, 2024
3 checks passed
@mjgiarlo mjgiarlo deleted the destroyable-related-links#183 branch November 26, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow nested attributes to be deleted
2 participants