pwFoo Posted January 1, 2015 Share Posted January 1, 2015 At first... I wish you all a happy new year!!! I testing the dev updates to form api (array input) and also would try to remove a required field before send / render the form. In the past version(s) a previously added field couldn't simply removed if it was a required field. During form process the removed field input was checked because it's required... But the field was removed before render it... Now I updated to the latest dev to test array field input and also the remove field from form behavior... // page to work with $refPage = $pages->get(1012); $form = $modules->get("InputfieldForm"); // submit button as array $submitBtn = array( 'id' => 'submit', 'name' => 'submit', 'value' => 'Submit', 'type' => 'InputfieldSubmit', ); // add fields from a defined page $refPage and the submit button to form $form->add($refPage->getInputfields()); $form->add($submitBtn); // modify the form: remove title field $toRemove = $form->get('title'); $form->remove($toRemove); // render modified form - title field should be removed and no more required... but still rendered!!! $out = $form->render(); Why the title field isn't removed from the form Is it a bug at PW dev? Or is there an error at my code? Because field isn't removed at the moment I can't test if a removed required field is handled as required during form process... So that would be the second step to test Link to comment Share on other sites More sharing options...
pwFoo Posted January 1, 2015 Author Share Posted January 1, 2015 As before I'll generate a field list before I add to form... Instead of use getInputfields() I'll use a find to select / remove fields. $selectedFields = $refPage->fields->find('name=title|body|image, name!=title'); Selector part will be generated dynamic to make it flexible. Because PW form api works with array input I'll simplify my FormHelper to use the existing array syntax instead of my own. Link to comment Share on other sites More sharing options...
adrian Posted January 1, 2015 Share Posted January 1, 2015 The easiest way to do that is: $fieldsToIgnore = array('title'); $fields = $refPage->getInputfields(); foreach($fields as $f){ if (!in_array($f->name, $fieldsToIgnore)){ $form->append($f); } } 1 Link to comment Share on other sites More sharing options...
pwFoo Posted January 2, 2015 Author Share Posted January 2, 2015 Hi adrian, thank's. I know this way and have decided to use it again / furthermore You're right, should be the easiest way to do it. Tried another way which also works, but because of missing page / template context (I think...) there are some limitations (missing options,...) and so there should be no real gain compared to array created fields. Example from inside a testing module. $fields = $this->fields->find('name={$fieldSelector}, name!=title'); // title doesn't work!!! foreach ($fields as $field) { $inputfield = $modules->get($field->inputfieldClass); $form->add($inputfield); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now