Skip to content

chosen.js not initialized when display-if field is toggled #882

@dlh01

Description

@dlh01

Description of the bug

When a select field using both type_ahead and display_if is initially hidden, chosen.js isn't initialized when the field is shown.

Steps To Reproduce

Test with this group by saving it with disable_blocks enabled, and you should see that the typeahead UI on disable_block_terms isn't initialized on the next pageload after unchecking disable_blocks:

new Fieldmanager_Group(
	[
		'label'    => 'Ads',
		'children' => [
			'disable_blocks'  => new \Fieldmanager_Checkbox( 'Disable all blocks' ),
			'disable_block_terms' => new Fieldmanager_Select(
				[
					'label'      => 'Disable blocks on these categories',
					'datasource' => new Fieldmanager_Datasource_Term(
						[
							'taxonomy' => 'category',
						],
					),
					'display_if' => [
						'src'   => 'disable_blocks',
						'value' => '0',
					],
					'multiple'   => true,
					'type_ahead' => true,
				],
			),
		],
	]
)

Additional Information

Adding fm_displayif_toggle to this list seems to fix the problem:

$('.fm-wrapper').on("fm_added_element fm_collapsible_toggle fm_activate_tab",".fm-item",function(){

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjavascriptRequires understanding JavaScript

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions