Jump to content

[SOLVED]Custom input areas in fields 'details tab' not getting saved


Recommended Posts

I've noticed custom input areas or InputfieldText rendered in InputfieldMarkup and added to a fields 'details tab' are not getting saved when the field is saved. The values are sent alright. I can't find where and why in ProcessField.module ProcessWire is discarding them...The code below doesn't work...

public function ___getConfigInputfields(Field $field) {
  $f = $this->modules->get("InputfieldText");
  $f->attr('id+name', 'test');
  $f->attr('value', $field->test);
  $f->label = $this->_('Test');

  // ALTERNATIVE TO ABOVE..hence same 'name' (NOT being used together)
  $customInput = '<input type="text" name="test" value="'. $field->test .'">';

  $markup = $modules->get('InputfieldMarkup');
  #$markup = new InputfieldMarkup;
  $markup->attr('id', 'my_test_markup');
  #$markup->attr('value', $f->render());// @note: input rendered but value not saved
  #$markup->value = $f->render();// @note: input rendered but value not saved
  $markup->attr('value', $customInput);// @note: input rendered but value not saved
  //$markup->value = $customInput;// @note: input rendered but value not saved

  $inputfields->append($markup);// @note: input rendered but value not saved

  //$inputfields->append($f);// normal method works

  return $inputfields;

} 

Any ideas or this is it? Thanks.

Edited by kongondo
Link to comment
Share on other sites

I think this is possible like this. There's no fields PW sees and knows about, just custom markup. I think you'd have to use inputfields or maybe save the values yourself.

Link to comment
Share on other sites

Thanks Soma. I wish there was a way to let PW see my custom markup. 

Edit:

The reason I need my own markup is so that I can tightly control the layout using a table. I have noticed even Inputfields in MarkupAdminTables don't get their values saved. For now, I think for each of my custom inputs I'll create an InputfieldHidden which will get updated with the value of its paired custom input (using jQuery). The InputfieldHidden will get saved and the custom input will display the saved value...

Edited by kongondo
Link to comment
Share on other sites

The thing is ProcessWire is evaluating all the fields, which are part of the form object and nothing more. You could try to hook before processInput() or alike and add those inputfields for real, so they can be saved even if those weren't used previously to generate the frontend representation.

  • Like 3
Link to comment
Share on other sites

Thanks Benjamin, below works a treat in my limited tests
 

public function ___getConfigInputfields(Field $field) {

   // code to build custom inputs....

   // hook into process
   #$this->addHookAfter('ProcessField::fieldSaved', function($event) {// either works...
   $this->addHookBefore('ProcessField::fieldSaved', function($event) {
   $field = $event->arguments(0);
   $field->test='testing testing';// values will be coming from $this->wire('input');
   $field->save();

});

 return $inputfields;
 
} 
Edited by kongondo
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...