Jump to content

Integrating working "required if" conditions in repeater


Juergen
 Share

Recommended Posts

It would be great if  "required if" conditions in repeaters inputfield dependencies will work in the future. At the moment only "show if" conditions work.

Today I have implemented the new fieldset  (Page) type, which works like a repeater. But unfortunately I had to remove it because of the non working "required if" conditions. In my case I need the "required if" condition and therefore I had to switch back to a default fieldset (which supports the "required if" condition dependency). But it was more work and I needed more fields.  

So this feature would save a lot of time. Maybe it will be possible in the near future. Would be great!

  • Like 1
Link to comment
Share on other sites

6 hours ago, Juergen said:

But unfortunately I had to remove it because of the non working "required if" conditions. In my case I need the "required if" condition and therefore I had to switch back to a default fieldset (which supports the "required if" condition dependency). But it was more work and I needed more fields.  

why don't you use a hook to set the required attribute based on your condition? sounds easier than your way ;)

  • Like 1
Link to comment
Share on other sites

I have created a set of inputfields for recurring events. There you can choose between daily, weekly, monthly yearly and you can choose between an enddate or a number of repeats (and of course some other options).

The if condition depends on a select option fieldtype. If you choose "repeat until a certain enddate" then the enddate field needs to be filled out (required), if you choose to repeat the events until a certain number of repeats (fe 10 repeats), then the enddate field is not required.

All the fields are in the new fieldset(Page) fieldtype.

 

Link to comment
Share on other sites

  • 1 month later...
On 27/9/2017 at 2:28 PM, bernhard said:

why don't you use a hook to set the required attribute based on your condition? sounds easier than your way ;)

Hello. I have the same problem: i want to require a filed into a repeater.... an hook?... do you may put a simple approach?

I have try with this not working code into ready.php
 

$wire->addHookAfter('FieldtypeRepeater::savePageField', function($event) {
  	$items=($event->arguments[0]->links_utili);
  	foreach ($items as $key) {
  		if (empty(trim($key->title)) || empty(trim($key->url_link)){
  			//i need to remove the field and show a warning message
  		}
  	}
});

I have a repeater named links_utili with 3 fields: title, url_link, active and i want to require url for each title
This is the correct approach or is better to implement 

$this->addHookBefore('Pages::save', function(HookEvent $event) 

 

Thank you

Link to comment
Share on other sites

On 27/11/2017 at 3:52 AM, abmcr said:

i want to require a filed into a repeater

Required fields work fine in a repeater. From what I have tested, "required if" dependencies also seem to work fine in a repeater. What problem do you get if you make the url_link field required in your repeater?

Link to comment
Share on other sites

  • 2 years later...

It's an old topic, but I have nearly the same problem:

When using condition the conditon "required if" I'll get an error displayed:

Quote

FieldtypeRepeaterConfigHelper: Repeater-Feld "images" hat in den Einstellungen eine Bedingung "Pflichtfeld nur wenn", dies wird in Repeatern nicht unterstützt. +1
FieldtypeRepeaterConfigHelper: Repeater-Feld "videos" hat in den Einstellungen eine Bedingung "Pflichtfeld nur wenn", dies wird in Repeatern nicht unterstützt.

but it seems to work ?

Unfortunately I was wrong, when saving the page PW tells me that all these fields are required :

704521713_2020-03-0317_07_48.jpg.448633260af2819813996ed8d2229230.jpg

@ryan Could you shortly explain why we can't use "required if" conditions in repeater fields and if this may change in the nearer future?

Many greets !

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...