Jump to content
MarkE

Pre-populate InputfieldSelector

Recommended Posts

I am using InputfieldSelector in a custom module. I would like to pre-populate it based on a PW selector (e.g. "template=Booking, bookableSlotPage=8527, bookableSlotPage.tickets>0"). Using initValue will pre-select the template, but I would also like to have the initial display show the field filters as well. Is there a way of doing this in PW or do I need to devise some method of doing it with js?

By way of context, I am using this for dynamic email lists for my club membership system. The "dynamic" nature of the list is stored as a selector in a field which can then be used by the email function. To date, this has been done by just entering the selector as raw text. I now want to make this easier for 'normal' users by using the InputfieldSelector (in a runtime_markup field) to provide a user-friendly way of creating the selector. But then I need the page to show the initial InputfieldSelector to represent the selector stored in the field, for backwards-compatibility, if nothing else.

Share this post


Link to post
Share on other sites
3 hours ago, MarkE said:

I would also like to have the initial display show the field filters as well

Use the defaultSelector property instead of initSelector if you want the user to be able to see (and therefore change) the selector in the filters section.

Share this post


Link to post
Share on other sites
5 hours ago, Robin S said:

Use the defaultSelector property

Thanks, but I don't seem to be able to set that directly.

Share this post


Link to post
Share on other sites
47 minutes ago, MarkE said:

I don't seem to be able to set that directly

Oh right, I was thinking about InputfieldSelector in the context of Lister.

You just set the value of the inputfield:

$f = $this->wire('modules')->InputfieldSelector;
$f->name = 'test_selector';
$f->label = 'Test InputfieldSelector';
$f->value = "template=news_item, colours.title=Blue";

2020-02-15_233248.png.6e66cc2df2288a893e6ebf9bdd9cf7c3.png

  • Like 1

Share this post


Link to post
Share on other sites

Many thanks @Robin S. I had previously tried that, but it didn't work - hence my comment about not being able to set it directly. I now realise that the  cause of that was that I had previously set initValue, to disable changing the template. After that, setting value with the full selector does not work - it is necessary to first remove the "template=..." from the selector. Thanks for giving me the confidence that I was setting it correctly so that I persisted in hunting down the "feature".

So - adding a regex to split the selector into template (for initValue) and non-template (for value) components works a treat.

  • Like 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By SharQ
      Hi, 
      I've been trying to figure this out for two days now, but I cant seem to solve the issue without core modification, which is not the good way to go for sure. 
      I have nested hidden pages under a page called groups, and I customised the page lister module a bit extending the ProcessUser class (called processOffers) I have a custom JSTree module to select from these groups, so multiple selection is possible. My problem is,when click on the filters, and select groups in the lister module, I can see only the first level (which is a parent directory), but not the nested ones what I need. 
      I tried to catch the ajax call in my processOffers module, but seems like the control never reach my module, instead it goes to the InputfieldSelector::renderOpval straight, so I have no way to override it or write a hook or anything. 
      One thing I noticed is if I copy the ajax query and paste it into my browser url, it invokes my processOffers class, but it doesn't do it if I do it via ajax!
      ( ...backend/offers/?InputfieldSelector=opval&field=groups&type=&name=filters)
       > Update: Okay, so this one is because of the X-Requested-With:XMLHttpRequest header. 
      How could I list the nested pages as a flat list or
      how could I interact with this ajax call to override the result? 
    • By Orkun
      I've created a custom process module, which the user can manage form-entries. In my executeEntries function, I've created a custom InputfieldSelector(should serve as real-time-search) and a custom MarkupAdminDataTable(serves as Resulttable) which holds the entries. How is it possible to combine the InputfieldSelector with the MarkupAdminDataTable?
      How can I get the selector from the InputfieldSelector? How can I convince the MarkupAdminDataTable, that he uses the new selector from the InputfieldSelector every time when I change the filters in the InputfieldSelector? public function executeEntries:
      public function executeEntries(){ $this->fuel->breadcrumbs->add(new Breadcrumb('./', 'Event-Manager')); $this->fuel->breadcrumbs->add(new Breadcrumb('./', 'Dashboard')); $this->fuel->set('processHeadline', 'Formulareinträge Event-Formular'); $form = $this->modules->get("InputfieldForm"); $form->method = "post"; $form->attr('id',$this->className()); $fieldset = $this->modules->get("InputfieldFieldset"); $fieldset->label = "Suche"; $fieldset->collapsed = Inputfield::collapsedNo; $field = $this->modules->get("InputfieldSelector"); $field->label = "Filter"; $field->attr("name+id", "filters"); $field->setAttribute("value", "template=50"); $allowedFields = array(); $formtemplate = $this->templates->get("name=form-submission"); foreach ($formtemplate->fields as $fieldN) { $allowedFields[] = $fieldN->name; } array_push($allowedFields, "template"); $field->limitFields = $allowedFields; $fieldset->add($field); $entries = $this->pages->find("template=form-submission"); $table = $this->modules->get("MarkupAdminDataTable"); $table->headerRow( array("Name", "Erstellt", "Aktionen") ); $table->setEncodeEntities(false); $table->action(array('Als Excel exportieren' => "./export")); foreach($entries as $entry){ $data = array( $entry->title, date("d.m.Y H:i:s", $entry->created), "<a href='showentry?id=$entry->id'>Details anzeigen</a> | <a href='./editentry?id=$entry->id'>Bearbeiten</a>", ); $table->row($data); } $preview = $this->modules->get("InputfieldMarkup"); $preview->value .= "<h2>" . $this->_("Formulareinträge Event-Formular") . "</h2>"; $entriesLimit = 20; $entriesOffset = ($this->input->pageNum - 1) * $entriesLimit; $entriesTotal = count($entries); $preview->value .= sprintf($this->_("Anzahl der Einträge: %s"), $entriesTotal); $preview->value .= " | "; $preview->value .= sprintf($this->_("Anzahl pro Seite: %s"), $entriesLimit) . "<br/>"; $preview->value .= $table->render(); $pagination = new PageArray(); $pagination->setTotal($entriesTotal); $pagination->setLimit($entriesLimit); $pagination->setStart($entriesOffset); $preview->value .= $pagination->renderPager(); $form->add($fieldset); $form->add($preview); return $form->render(); } How the Interface looks like:

    • By isellsoap
      Today I discovered the module FieldtypeSelector and at first sight I didn’t know how to make use of a field of this type inside a template, respectively if there are good and smart use cases for it (I’m sure there are). Do you know of any?
      (Interestingly enough I could not find a single blog or forum topic/post discussing this module in the context of template development.)
      I would be also interested in some (pseudo-)code examples to get a better idea of how I could integrate this field type in my template workflow. Thanks a lot in advance.
×
×
  • Create New...