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

Add ability to exclude fields from rendering. #77

Merged
merged 1 commit into from
Apr 18, 2015
Merged

Add ability to exclude fields from rendering. #77

merged 1 commit into from
Apr 18, 2015

Conversation

theshaunwalker
Copy link
Contributor

Adds logic to Form, ChildFormType and respective views, to add the ability to mark fields to not render when calling ->renderForm() or ->render().

When using with Form:

$form->exclude(['unwanted_field', 'another_field'])->renderForm();

When using with ChildFormType:

$form->child->render(
  ['exclude' => 
    ['unwanted_field', 'another_field']
  ]);

Not experienced with phpunit for testing so havnt included tests as when I tried to copy another test and tweak to fit this use-case, Mockery was throwing stuff at me that I dont know how to solve :P

@theshaunwalker
Copy link
Contributor Author

Apologies for the multiple commits, forgot I should probably run phpunit locally at least before pushing :P

@kristijanhusak
Copy link
Owner

This is good idea, but it may be problem when renderRest is called, it will find those fields and render them, because they will be excluded and not marked as already rendered. Maybe instead of creating exclude property that holds these fields, just to use remove() method which will remove those fields from the fields array.

@theshaunwalker
Copy link
Contributor Author

I thought about that but it shouldnt be an issue, as it adds the exclude check to the views as well so as long as the field is still in the $exclude array then the field shouldnt get rendered in any scenario.

I dont want to remove the fields completely, just exclude them from the general "render all the form" functions as it provides the flexibility to cherry pick fields I'm going to do other stuff with.

My current use-case is I exclude a field from one form's render() because I render that specific field elsewhere on the page.

@kristijanhusak
Copy link
Owner

You're right. Merging it. Thanks!

kristijanhusak added a commit that referenced this pull request Apr 18, 2015
Add ability to exclude fields from rendering.
@kristijanhusak kristijanhusak merged commit 411977e into kristijanhusak:master Apr 18, 2015
@theshaunwalker theshaunwalker deleted the feature-except-rendering branch April 19, 2015 14:37
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.

None yet

2 participants