Can you pass a parameter to a selection factory?

Vote:
 

Hi,

I have a block property that uses a selection factory to provide a SelectOne and the data returned from the selection factory needs to be filtered based on the value of another property on the block.

Is this possible? If so how?

Thanks in advance,

Mark

#179509
Jun 14, 2017 13:39
Vote:
 

Hi,

One way would be to get access to page itself and then check value of the property:

public class SomeSelectionFactory : ISelectionFactory {
    public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
    {
        // depending on master language - returning some stuff
        var masterLanguage =
 ((PageData)metadata.Parent.Model).MasterLanguage;

        ....
#179516
Jun 14, 2017 15:05
Vote:
 

But this apporach is fragile in sense that child-parent depth is not deterministic. From the selection factory perspective you cannot be sure that 1st level parent will always be page itself (thinking about local blocks..).

#179517
Jun 14, 2017 15:07
Vote:
 

Thanks Valdis, that approach was so close to being able to acheive my result. I can get the value I need but if I then change it, it doesn't hit the selection factory again until after a publish so the list does not get updated based on the new value selected.

#179520
Jun 14, 2017 16:43
Vote:
 

May be this will be useful :-)

https://gregwiechec.com/2017/06/how-to-create-selectionfactory-with-parameters/

#179527
Jun 14, 2017 17:39
Vote:
 

Hi Tahir,

That's useful thanks but not quite what I'm after. I need a list to be populated based on the value selected in another property, I kind of have this working but the selection factory is not called if I update the selected value of the other property.

Thanks,

Mark

#179559
Jun 15, 2017 10:34
Vote:
 

Hi,

You can try http://nuget.episerver.com/en/OtherPages/Package/?packageId=DependentSelection and see if it works for you.

Disclaimer: I am the creator of this package. I mostly created it to test creating a EPiServer addon, so I cant guarantee that it works in all versions(10.x) of epi.

/Peter

#179562
Jun 15, 2017 10:56
Vote:
 

Hi Peter,

This looks interesting.. :) Mind if I do code review? :))

#179564
Jun 15, 2017 11:12
Vote:
 

Hi Peter,

That does sound good, sadly we're on an earlier version of EPiServer (7.19) at the moment.

#179565
Jun 15, 2017 11:19
Vote:
 

ouch, that's vrsion I haven't seen for a while :)

#179566
Jun 15, 2017 11:24
Vote:
 

Sure, go ahead Valdis:)

Mark, you might need to create a custom editor if you want the options to be updated without reloading the ui. Maybe http://world.episerver.com/Blogs/Duong-Nguyen/Dates/2014/1/Country-Region-drop-down-lists-in-All-properties-mode/ can help. I can't remember what works and what doesn't work in 7.x

/Peter

#179578
Jun 15, 2017 13:41
Vote:
 

Hi, is there any new / updated suggestion please ?

#192085
May 05, 2018 16:35
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.