• Hi Ovan,

    can you tell me if it is possible to add Values to the list dynamically populated dropdowns of a list field?

    I have used your code: gform_pre_render and I can load the form with options but how can I add a value to each option?

    Thank you!

    Best regards
    Amer

Viewing 1 replies (of 1 total)
  • I too couldn’t believe that after nearly a year that this is still not supported. It’s such a big oversight.
    Anyway, in his example pre_render hook example, which is simplified:

    
    	if ( GFCommon::is_form_editor() || $YOUR_FORM_THAT_YOURE_TARGETTING != $form['id'] ) {
    			return $form;
    		}
    
    		if ( is_array( $form ) || is_object( $form ) ) {
    
    			foreach ( $form['fields'] as &$field ) {  // for all form fields
    				$field_id = $field['id'];
    				if ( YOUR_FIELD_ID_THAT_YOURE_TARGETTING != $field_id ) {
    					break;
    				}
    
    				if ( 'list' == $field->get_input_type() ) {
    
    					$has_columns = is_array( $field->choices );
    
    					if ( $has_columns ) {
    						$array = [];
    						foreach ( $field->choices as $key => &$choice ) { // for each column
    							$isDropDown = rgar( $choice, 'isDropDown' );
    							if ( $isDropDown ) {
    // basically, this is where the magic has to happen. Build up your array with value and text options and then finally append it onto $choice['isDropDownChoices'].
    								$array[] =['value' => 0, 'text' => 'first choice'];
    								$array[] =['value' => 10, 'text' => 'second choice'];
    								$array[] =['value' => 20, 'text' => 'third choice'];
    
    								$choice['isDropDownChoices'] = $array;
    							}
    						}
    					}
    				}
    			}
    		}
    		return $form;
    
    • This reply was modified 6 years, 1 month ago by proximity2008. Reason: explanations
    • This reply was modified 6 years, 1 month ago by proximity2008.
    • This reply was modified 6 years, 1 month ago by proximity2008.
Viewing 1 replies (of 1 total)
  • The topic ‘Add Values to Label’ is closed to new replies.