Jump to content

Pre-populate InputfieldSelector


MarkE
 Share

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.

Link to comment
Share on other sites

  On 2/15/2020 at 9:43 AM, MarkE said:

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

Expand  

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

×
×
  • Create New...