NF_Fields_ListMultiselect

Class NF_Fields_MultiselectList.

Defined (1)

The class is defined in the following location(s).

/includes/Fields/ListMultiSelect.php  
  1. class NF_Fields_ListMultiselect extends NF_Abstracts_List 
  2. protected $_name = 'listmultiselect'; 
  3.  
  4. protected $_type = 'listmultiselect'; 
  5.  
  6. protected $_nicename = 'Mulit-Select'; 
  7.  
  8. protected $_section = 'common'; 
  9.  
  10. protected $_templates = 'listselect'; 
  11.  
  12. protected $_old_classname = 'list-multiselect'; 
  13.  
  14. public function __construct() 
  15. parent::__construct(); 
  16.  
  17. $this->_nicename = __( 'Multi-Select', 'ninja-forms' ); 
  18.  
  19. add_filter( 'ninja_forms_merge_tag_calc_value_' . $this->_type, array( $this, 'get_calc_value' ), 10, 2 ); 
  20.  
  21. public function admin_form_element( $id, $value ) 
  22. $field = Ninja_Forms()->form()->get_field( $id ); 
  23.  
  24. $options = ''; 
  25. foreach( $field->get_setting( 'options' ) as $option ) { 
  26. $selected = ( in_array( $option[ 'value' ], $value ) ) ? "selected" : ''; 
  27. $options .= "<option value='{$option[ 'value' ]}' $selected>{$option[ 'label' ]}</option>"; 
  28.  
  29. return "<select class='widefat' name='fields[$id]' id='' multiple>$options</select>"; 
  30.  
  31. public function get_calc_value( $value, $field ) 
  32. $selected = explode( ', ', $value ); 
  33. $value = 0; 
  34. if( isset( $field[ 'options' ] ) ) { 
  35. foreach ($field['options'] as $option ) { 
  36. if( ! isset( $option[ 'value' ] ) || ! in_array( $option[ 'value' ], $selected ) || ! isset( $option[ 'calc' ] ) ) continue; 
  37. $value += $option[ 'calc' ]; 
  38. return $value;