The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Select an entry from the same form in a Dynamic View

Labels

This Discussion is public

Notifications

I'm a little confused of what to do here, I hope some of you have an answer.

I have a big list of members in a form. Among other data, one of the fields is a Toggle "Is Coach?" field. Another field (all in the same form) is a Dynamic Field: Coach.

With this setting I mean that any member can be a coach of any other member, but there are limited coaches, let's say 20 of 100 members. So, the "Is Coach?" field designs that this member will appear in the dropdown of the Coach field in the same form.

And it works, except that I can't narrow the list of coaches according to the "Is Coach?" Toggle field.

I tried with the hook that is in: Formidable Hooks - for Developers → Field Options and Values → frm_setup_new_fields_vars → Filter Dynamic Field.

This hook is supposed to filter the options of a Dynamic field by watching another field in the linked form, but I'm using here the same form, and I don't know if that could be the problem.

Can someone point me in the right direction to make this happen? Thanks in advance.

Setup:

FORM: Members

Name (Text field)

Is Coach? (Toggle field)

Coach: (Dynamic Field - dropdown ) Load options from Form entries - Form: Members - Field: Name. This field will be filtered according to "Is Coach?" field set to active.

First off, the dynamic field is going to be pulling data that has already been saved. An entry will not show in the dynamic field, unless it has been saved to the database prior to selection.

Do you understand that?

Can you export the form for troubleshooting?

Yes, I can understand that but, you see, the entry is not supposed to call itself (because no one can be his own coach). It is supposed to list all other entries (Name field) whose Is Coach? field is set to Active (and obviously has been previously saved.

The thing is that all of them (coaches and coached) are members in the same list. I think it's redundant to make another list with the same fields (there are another fields in the form, address, age, etc). Unless is something obvious that I'm missing.

Posting the example form in the next comment.

This is the example form. I think the idea is understandable. Thanks in advance.

I'm not sure if the file was attached, if not, tell me what to do to attach it (it's an xml file).

Again, in a zip file.


Attachment:
controljet.formidable.2018-05-08.zip

You'll have to incorporate this code snippet from the knowledgebase for that kind of filtering:

add_filter('frm_setup_new_fields_vars', 'filter_dfe_options', 25, 2);
function filter_dfe_options($values, $field){
if ( $field->id == 1155 && !empty( $values['options'] ) ) {//Replace 1155 with the ID of your Dynamic field
$temp = $values;
$temp['form_select'] = 1154;//change 1154 to the id of the field (in linked form, the yes/no field) that you want to filter by
$field2_opts = FrmProDynamicFieldsController::get_independent_options( $temp, $field );
foreach ( $values['options'] as $id => $v ) {
if ( isset( $field2_opts[$id] ) && ( $v == '' || $field2_opts[$id] == 'Yes' ) ) {//Only include values where filtering field equals Yes
continue;
}
unset( $values['options'][$id] );
}
}
return $values;
}

Reference: https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/#kb-filter-dynamic-field

Oh... it worked! But with a strange exception.

If you read my original message, I have tried the same code before and I thought it hadn't worked. The form that I posted here is a new one for testing and it worked ok with the code snippet. Then I tried it in my real form and apparently it won't work. But it wasn't true:

I have discovered that the reason is that I already had some members entries in the database, with the dynamic field selected, before the code was introduced. Now, when I edit the previously captured entries, the dynamic field shows no filter. But when I add a new entry, it filters perfectly. Fortunately this is a work in progress and the no-filtering does not affect anything, but I wonder why is this.

So, it only works with new entries. If you have a clue for why this happens, it will be nice to know it.

I imported the form and entries and then applied the code later, so my entries were "old" data. I don't see why the code would only reference new entries in examining the code provided. It doesn't say anything about any specific date of data, it is only looking for "yes" in the field referenced second. You'll have to further look at your data and try to figure it out. Pull up an entry that isn't working and temporarily switch the value to no, save, and then switch it back to yes and see what happens.

Yes, that's what I've thought, but it's happening. I'll keep experimenting and will post here any discovering. Thanks!

Hi Bobby, sorry to bring up this issue some months later, but I've retaken the project where the issue happens.

The one I sent you was a test, and it worked fine with the exception that I mentioned. So the problem was solved when erasing all data and starting again. But I forgot this and stumbled across with the issue again, I tried to implement it in the real working site when there's some data already entered and... it keeps happening.

It's not really a big problem because there are still a few entries, but the field to filter keeps showing ALL values when editing any old entry, but works fine if I create a new one. It's puzzling for me because, as you said, the code does not reference the date of data in any way. But it's happening, though.

It won't work to switch or change values on any entry. So my guess is that, for an unknown reason (far from my experience to understand), the code only filter the values in the creation of an entry, not when updating an existing one. If you may want to take a closer look to this case, please tell me. :)

Julius,

Have you at this point posted this on the official help desk?

I would say you need to export your data, combine it with the new data, and then re-import it as though everything is new. Be sure to have a backup to restore, just in case.

Bobby

Sorry but I have discovered that is not exactly how I believed.

What is really happening is that the field becomes correctly filtered ONLY in new entries, not when updating an old one. So, when I create a new entry, it just shows the desired values. But when I try to update the field now is showing ALL values. So there is a problem in the code or something.

I'm going to post it in the official help desk, but it would be worth you give it a try.

Thanks for following this.

Discussion closed.