Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Stefan
Developer

Hi Alco,

I think this is possible. The only editable type that allows you to switch between two values is the type ‘toggable’. We use this for setting booleans to true/false, yes/no or 1/0. If you really have only two option to choose from, you can use this toggable to switch between those values.

First you need to set the editable type to ‘togglable’ for you (specific) columns by using the ‘cac/editable/option‘ filter. You could use something like this.

function my_set_editablie_custom_field_to_toggle( $editable, $column ) {

	if ( 'status' == $column['field'] ) {
		$editable['type'] = 'togglable';
		$editable['options'] = array( 'open', 'betaald' );
	}
	return $editable;
}
add_filter( 'cac/editable/options', 'my_set_editablie_custom_field_to_toggle', 10, 2 );

Based on your screenshot, I don’t know much about your columns, so you have to tweak it a little bit to run this code only for your column (in my example a Custom Field column with field set to ‘status’).

After that you can use ‘cac/inline-edit/ajax-column-save/value‘ filter to change the value just before it is saved to the database.

function cac_editable_ajax_column_save_toggle_status( $value, $column, $id ) {

	if ( 'status' == $column->get_option( 'field' ) ) {
		// Get current value
		$value = $column->get_value( $id );
		if( 'betaald' == $value ){
			$value = 'open';
		} else {
			$value = 'betaald';
		}

	}
	return $value;
}
add_filter( 'cac/inline-edit/ajax-column-save/value', 'cac_editable_ajax_column_save_toggle_status', 10, 3 );

Also here you have to figure out your own columns check instead if using my ‘status’ check.

5 years, 4 months ago
Alco

Hi,

Great this helped a lot.
But I had to add a filter for the column value so I get the correct status:

/**
	 * Display text notifying the user that no image is available
	 *
	 */
	static public  function factuur_status_action_change_column_value( $value, $object_id, $column, $storage_key ) {
		
		if ( 'factuur_status' == $column->get_option( 'field' ) ) {
			
			$factuur_status = get_field('factuur_status', $object_id);
			
			if( $factuur_status == 'open' ){
				$value = '<span class="dashicons dashicons-no cpac_status_no"></span>';
			}
			else if( $factuur_status == 'betaald' ){				
				$value = '<span class="dashicons dashicons-yes cpac_status_yes"></span>';
			}
						
			//$value = '<em>' . __( 'No featured image', 'myplugin' ) . '</em>';
		}
		return $value;
	}

This works great on page reload, but not when I save the value. The ajax value is saved, but the wrong icon is displayed.
Is it possible to display an other icon after ajax save?

5 years, 4 months ago
Stefan
Developer

Hi Alco,

You can use this filter to get the correct value. cac/column/value (documentation)

5 years, 4 months ago
Alco

Hi Stefan,

This works after page reload but not when I click & get the value via acf fields.
Is it possibille to get the rawvalue of the object? This value is correct in the json response & is something I could use good.

5 years, 4 months ago
Stefan
Developer

Yes, you could use this code to get the correct value after using a ajax inline edit save.

function cac_get_status_raw_value( $contents, $column, $id ) {

	if ( 'factuur_status' == $column->get_option( 'field' ) ) {
		$contents = $column->get_raw_value( $id );
	}
	return $contents;
}

add_filter( 'cac/editable/after_ajax_column_save/value', 'cac_get_status_raw_value', 10, 3 );
5 years, 4 months ago
Alco

Hi,

With the following code it works perfect :)

cac_get_status_raw_value( $contents, $column, $id ) {

		if ( 'factuur_status' == $column->get_option( 'field' ) ) {
			$raw_value = $column->get_raw_value( $id );
			
			if( $raw_value == 'open' ){
				$contents = '<span class="dashicons dashicons-no cpac_status_no"></span>';
			}
			else if( $raw_value == 'betaald' ){				
				$contents = '<span class="dashicons dashicons-yes cpac_status_yes"></span>';
			}
			
		}
		
		return $contents;
	}
5 years, 4 months ago
Stefan
Developer

Hi Alco,

Great that it’s working now.
I will mark this topic as resolved.

5 years, 4 months ago

You must be logged in to reply to this topic.