Jump to content
ryan

Field Dependencies

Recommended Posts

It shouldn't matter on which pages the dropdowns are. Only the relation (parent/child) between the choosable pages must be correct.

Share this post


Link to post
Share on other sites

I've posted question this in the Padloper forum, but realized it might not be Padloper specific so thought I would try here too.

The module uses a template to generate a form populated with the template fields on the front end, by default these are for a billing address. Really simple form validation is done by making specific fields required, this all works as it should. However I'm attempting to extend this to include a shipping address.

I have a checkbox called "shipping_toggle" which when checked reveals further fields for an alternative shipping address using JS. I need these fields to be required ONLY if the "shipping_toggle" checkbox is checked. I've tried setting these fields as required with the condition that "shipping_toggle=1" in the template but they seem to always be required when the form validates, even with this condition set.

Apologies if this is module specific, it seems to validate the form using $form->processInput() which I believe is a PW core method, but I could well be wrong.

EDIT
Turns out this wasn't a Padloper issue or a problem with field dependencies. I had the following code in my config.php to allow for field dependencies in repeaters, luckily we've moved all the repeaters over to PageTables for this project, so I was able to remove it.

$config->InputfieldWrapper = array(
    'useDependencies' => false,
    'requiredLabel' => 'Missing required value', 
);

 

Edited by POWERFULHORSE
Identified Issue

Share this post


Link to post
Share on other sites

Hi,

I'm kind of a pw-rookie, it means I only created some (simple) projects with this fantastic cms. But now I need a different and difficult data structure and have a question regarding field dependencies in admin area.

I have different data trees. Schema:

one
-one-1
--one-1-1
--one-1-2
--one-1-3
-one-2
--one-2-1
--one-2-2
--one-2-3

two
-two-1
--two-1-1
--two-1-2
-two-2
--two-2-1
--two-2-2

data
-item-1
-item-2
-item-3

"one" and "two" are base data trees, tree "data" is for later frontend output. Now I have in "one-1-1" a page field named "value-type". There I have to choose a value: "two-1" or "two-2".

Now I edit "data-item-1". There I have to choose "one", "one-1" and "one-1-1". No problems there. In admin field properties I use the custom selector to find selectable pages (parent=page.fieldname).

Now I want to choose the "two-x-x" value in "data-item-1" depending on the one-1-1 selection. I tried something like parent=page.fieldname.value-type, but it seems to be not possible. What should I do, if I want to get the parent page ("two-1" or "two-2") to make the children selectable for me? Any suggestions?

Kind regards,

Thomas

Share this post


Link to post
Share on other sites

@Fantomas, welcome to the PW forums! :)

I found your post difficult to follow because of the page names you have used in your example. It would be easier to grasp what you're trying to do if you use demo names that can have some meaningful relation, e.g. "Cars", "Model", "Colour", etc.

The thing you're asking about is not the basic inputfield dependency feature that this thread introduces, but is actually a feature of Page inputfields. The trouble is that the feature is not formally documented anywhere (grumble, grumble) - it just pops up in forum discussion - so it's difficult to know exactly what is and isn't possible in terms of this feature.

As I understand it, the feature only works in the "Custom selector to find selectable pages" (not in "Custom PHP code to find selectable pages") and the reference can only be to another Page field that is in the page being edited. If you're wanting to reference the value of a Page field on a different page then you can do this with FieldtypeReference (and maybe RuntimeMarkup also, not sure).

 

  • Like 2

Share this post


Link to post
Share on other sites
On 11/30/2013 at 7:52 PM, ryan said:

Actually, you can do this on the dev branch. Lets assume that cities are children of countries and that is reflected in your page structure (i.e. /countries/france/paris/). Create your 2 page fields (country and city), and configure 'country' as a single page field with "parent" set to "/countries/". Next, for the "city" field configuration, use the "Custom selector to find selectable pages", present on the "input" tab. In that field, enter "parent=page.country". Save and try it out. This works with select, selectMultiple and asmSelect fields (and possibly others), though not yet with checkboxes, radios or PageListSelect. 

This works perfectly! BUT, still doesn't work with checkboxes. Is there any way to make this method to work with checkboxes or radiobuttons?

Thanks!

Share this post


Link to post
Share on other sites

Hi Guys

The field dependencies doesn't work for me when the "receiver" field is a "InputfieldRadios" field (the inputfields with the defined "showIf" Attribute are always hidden).
It only works when I change the "receiver" field to "InputfieldSelect".

   // Get repeater Pages as selectable Option
   if(count($page->rootParent->choose_sender_2016->contactform_receivers) > 1){
        $field = $modules->get("InputfieldRadios");
        $field->label = _gt("empfaenger");
        $field->attr('id+name', "receiver");
        foreach ($page->rootParent->choose_sender_2016->contactform_receivers as $option) {
            $field->addOption($option->id, $option->title);
        }
        if($input->get->receiver){
            $field->value = $input->get->receiver;
        }
        $field->required = 1;
        $form->append($field);
    }
    
    // triggerMedicalFields is a single page reference field which returns the repeater pages as selectable list (PHP Custom Code)
    if($page->triggerMedicalFields){

        $clinicSpecialities = $pages->find("template=specialities-clinics, choose_sender_2016={$page->rootParent->choose_sender_2016}");
        if($clinicSpecialities->count > 0){
            $field = $modules->get("InputfieldSelect");
            $field->label = _gt("fachgebiet");
            $field->attr('id+name', "speciality");
            foreach ($clinicSpecialities as $option) {
                $field->addOption($option->parent->id, $option->parent->title);
            }
            $field->required = 1;
            $field->showIf = "receiver={$page->triggerMedicalFields->id}";
            $form->append($field);
        }

        $field = $modules->get("InputfieldText");
        $field->label = _gt("krankheitsbild");
        $field->attr('id+name','disease_pattern');
        $field->required = 1;
        $field->showIf = "receiver={$page->triggerMedicalFields->id}";
        $form->append($field);

        $upload_path = $config->paths->assets . "files/-tmp_uploads/";
        $field = $modules->get("InputfieldFile");
        $field->label = _gt("medizinische-dokumentation");
        $field->required = 1;
        $field->attr("name+id", 'medical-documentation');
        $field->destinationPath = $upload_path;
        $field->extensions = "jpg jpeg gif png";
        $field->maxFiles = 3;
        $field->maxFilesize = 2*1024*1024; // 2mb
        $field->showIf = "receiver={$page->triggerMedicalFields->id}";
        $form->add($field);
        
    }

How can I make Inputfield Dependencies work with InputfieldRadios? I am using PW Version 2.7.3.

KR
Orkun

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...