XF 2.0 Options page - Node chooser defaults

AndyB

Well-known member
I would like to add a node chooser that is exactly like the one found in New posts widgets:

1541289521708.webp

Notice how it defaults to "All forums".

When I add a node chooser in the Options page it defaults to (None).

1541289723818.webp

Here's the code I'm currently using:

1541289656592.webp

What do I have to do so (None) becomes All forums?

Thank you.
 
Sorry, I had my post deleted before you replied. The ["0"] I suggested as a default, effectively pre-selects that (None) option.
It wasn't a valid answer to your question Andy so I got it scraped.

For your use case, you should probably use a Named Template as the Edit Format, and input the name of your custom template in the Format Parameters. (search templates named like option_template_* for some examples).

I'm not sure if the 'widget_def_options_new_posts' template could work out of the box as an option template.
 
The error says exactly what the issue is, you'll need a PHP callback function to get the list of nodes because "$nodeTree" doesn't exist unless it's being defined somewhere
 
The validation callback is for exactly what the name says. It is executed when the option is being saved, to check if the provided value is valid.
 
Check this out if it works the way you want it. A simple regex replace might do the job you want. Just note that the default value 0, is no more (None), but All forums when you'll be using it in your business code.

Screenshot from 2018-11-04 13-32-37.webp
 

Attachments

Back
Top Bottom