Support

Account

Home Forums Bug Reports Group settings field not saving

Solved

Group settings field not saving

  • Hello, I’m making a new custom field ( icon select ).
    I have added default_value like so:

    acf_render_field_setting( $field, array(
    			'label'			=> __( 'Default Icon', $this->textdomain ),
    			'instructions'	=> __( 'Select default icon', $this->textdomain ),
    			'type'			=> 'm7_acf_font_icon',
    			'name'			=> 'default_value',
    		) );

    [type=>m7_acf_font_icon is the same type as i’m creating. Basicaly it should call it self so that i could set default value by choosing it like when i’m editing post]
    So, when i’m on acf group creation ( post-new.php?post_type=acf-field-group ) or editing already existing group i can’t get value to save.. it alweys gives the default one.
    my code of echoing field ( render_field function ):

    function render_field( $field ) {
    		if( ! $this->icons || empty( $this->icons ) ) {
    			?><p><?php _e( 'There are no icons.', $this->textdomain ); ?></p><?php
    			return;
    		}
    		$value = $field[ 'value' ];
    		$groups = '';
    		$out = '';
    		$selected = '';
    		foreach( $this->icons as $group => $values ) {
    			if( ! $values || empty( $values) ) continue;
    			$groupName = ( isset( $this->files[$group] ) && isset( $this->files[$group]['name'] ) ) ? $this->files[$group]['name'] : preg_replace( '/([^a-zA-Z0-9])/', ' ', $group );
    			$groups .= '<option value="' . esc_attr( $group ) . '">' . $groupName . '</option>';
    			foreach( $values as $key => $data ) {
    				$class = '';
    				if( $value == $key ) {
    					$class = 'selected';
    					$selected = $data['html'];
    				}
    				$out .= '<li class="' . $class . '" data-value="' . esc_attr( $key ) . '" data-group="' . esc_attr( $group ) . '" data-search="' . $data['name'] . '" >';
    				$out .= $data['html'];
    				$out .= '</li>';
    			}
    				
    		} ?>
    		<div class="m7-acf-font-icon-wrapper">
    			<div class="acf-hidden">
    				<input type="hidden" name="<?php echo esc_attr( $field['name'] ) ?>" value="<?php echo esc_attr( $value ); ?>" class="m7-acf-font-icon-hidden" />
    			</div>
    			<div class="m7-acf-font-icon-header">
    				<span class="m7-acf-font-icon-preview"><?php echo $selected; ?></span>
    				<input type="text" class="m7-acf-font-icon-search" placeholder="<?php esc_attr_e( 'Search..', $this->textdomain ); ?>" value="" />
    				<select class="m7-acf-font-icon-groups">
    					<option value=""><?php _e( 'Filter by Group', $this->textdomain ); ?></option>
    					<?php echo $groups; ?>
    				</select>
    			</div>
    			<ul class="m7-acf-font-icon-body"><?php echo $out; ?></ul>
    		</div><?php
    	}

    as u can see only field that should submit is:
    <input type="hidden" name="<?php echo esc_attr( $field['name'] ) ?>" value="<?php echo esc_attr( $value ); ?>" class="m7-acf-font-icon-hidden" />
    but it’s not submited ( i checked with jquery (on form submit), after i click submit these input is .remove()’d from the dom ).

    Could u please explane how should i create hidden input on group edit screen so that it saves value ( bdw. on edit post page it saves value and works fine ).
    The problem is only with creating field – i cant get to set default value separet than i’v set in file ( i.e. select icon that will show by default ).

    Ok. If u understand the problem then please reply to me as soon as posible, if not understand – i’ll try to explane more.
    Already sped all night by trying to do saving and tiered (( help!

  • I found out that if on edit fields screen i edit only my custom field then the value is not submited, but if i trigger some othere property with it ( for ex. i have Return value ) then my custom field value updates to.
    I.e. if i change only my custom field – nothing, if i change return value and my custom field – my custom field value saves ok.

    Can u please tell me, do u have some check in js or semething like these ?
    may be in php before save_post action u check the variables ?

    becouse in save_post ( your’s ) i get my field without values submited ( if the’r not updated )

  • Finaly i found the problem!!

    omg how difficult it’s realised..

    So, as u know i had hidden input in my output ( render_field ) and as i understood it’s errasing is value not changed, so my problem was that wen in js i do $hiden.val( newVal ) the ‘change’ event is not fiered and ACF js files don’t see my input change and do not update value..
    So the solution was:
    $hidden.val( newVal ).trigger( 'change' );
    .trigger( ‘change’ )
    ( i’w been looking for that solution for few days, could be btter expaned in documentatoion how to make own custom fields )

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Group settings field not saving’ is closed to new replies.