Support

Account

Home Forums Feature Requests Feature Request: Hidden / Disabled Field Type

Solved

Feature Request: Hidden / Disabled Field Type

  • Hey @elliot

    Any plans on adding a “Hidden” or “Disabled” field type to the core? It would be quite useful to pass data along and store data, without having to use CSS/JS to hide or disable the field input from the backend, especially when using a repeater or flex field.

    For example, I recently used the update_field() function to update a repeater field and store external data in a couple of the columns. I wanted to show the data, but not make it ‘up-datable’ on the backend.

    As always, a million thanks for all your hard work on this plugin. Truly the best WP plugin ever.

  • Hi @Mike

    Nice. I’ll have a think about adding this in. Perhaps an option to disable a normal text field?

    Thanks
    E

  • @elliot,

    An option to disable a normal text field would be just fine! Thanks mate

    Mike

  • I’d like to second this; I’ve been needing it lately as well.
    I coded a manual hidden field type that stores the latest date each time the user saves the page for a client; I’m putting it on GitHub as we speak.

    It can be easily adapted to function just as a hidden field; look into the function update_value() on line 210 to accomplish this. Removing line 212 should do the trick 🙂

    Note that it might not be the most pretty solution (it’s the first field type I coded), but it works.

    I’ll take a look if I can tidy it up a bit; and built it into a plugin so that it’s easier to use. Hope you find it useful 🙂

    //edit: you can find the field type here: https://github.com/gport/acf-hidden-field

    //edit 2: if you look into the function create_field() on line 84, you can also change the output of the HTML. Currently, the hidden field is simply set as display: none, but you could easily remove this and disable the field as well.

  • Nvm. Posted this in the wrong place 😉

  • First, Awesome work on ACF!
    Just a Note: It looks like metaboxes aren’t honoring “Screen options” to turn on or off the metabox. While this works when the user clicks “Screen options” to hide a given metabox (jQuery toggles display:none/block), it’s not remembering the user set preferences.

    I’ve tracked the line down for you at line #714 in everything_fields.php. It looks like there is no initial style=”display: …” set. This needs to pull the user’s set value or leverage WP’s hidden_meta_boxes filter to know what the initial value is/should be.

  • Hi @s@Steveorevo,

    Thanks for tracking down the source for this one! I’ve passed a note onto Elliot.

    Cheers!!

  • Follow up. I’ve fixed the problem by changing line #302 in controllers/post.php from:

    $(‘#<?php echo $id; ?>’).addClass(‘<?php echo $class; ?>’).removeClass(‘hide-if-js’);

    to:

    $(‘#<?php echo $id; ?>’).addClass(‘<?php echo $class; ?>’);

    Not sure why hide-if-js was being removed. But this restored WP’s original screen options functionality without issues. ACF now honors screen options default settings and admin user-initiated settings. Thanks!

  • Hi @Steveorevo

    Thanks for your work on this one. I’ve added it to the to-do and will let you know if I find any issues with the fix.

    Thanks
    E

  • Hi @Steveorevo

    The above seems to work very well, and I can’t explain why I had chosen to remove the hide-if-js – perhaps an old decision to make sure ACF is always visible?

    This has been pushed to github and will be released soon.

    Thanks
    E

  • Hi @Steveorevo

    On further testing, I have found that the hide-if-js class causes many issue with ACF loading in new field groups via AJAX.

    I have reverted the commit and will keep this on the to-do to eventually find a solution, but for now I will not be able to provide a solution.

    Thanks
    E

  • I also could really use these options.

    It would be outstanding to, at some point in the future…

    1. Be able to make fields read only and do this based on current users role. Allowing admins to update a field and other roles just to view the field for example

    2. Hide fields based on user role. Same as above but hiding a field.

    For now would a cheap trick for hiding fields be to set conditional logic to an impossible combination on that field? So say show only if a select field which only allows selection of a single value is both option a and option b. This obviously only works if your form has a select field, though if you are hiding many fields might be worth adding a select field specifically for the job and hiding just that select field with css. Not tested this idea.

  • If you want a quick and dirty fix to add “edit” links to your repeater post selectors, add this snippet into the input.js file (adjust the wp-admin url if needed):

    /wp-content/plugins/acf-repeater/js/input.js

    on line 125 at the end of the render function

    /*EDIT LINK START*/
    			$('.repeater, .field_type-post_object').find('.post_object').each(function(){
    				var $editLink = $(this).parent().find('.edit-field-link');
    				if($editLink.length == 0)
    				{
    					$editLink = $('<a href="/wp-admin/post.php?post='+$(this).val()+'&action=edit" class="edit-field-link">Edit</a>');
    					$(this).before($editLink);
    				}
    			});
    			$('.repeater, .field_type-post_object').on('change','.post_object',function(){
    				var $editLink = $(this).parent().find('.edit-field-link');
    				$editLink.attr('href','/wp-admin/post.php?post='+$(this).val()+'&action=edit');
    			});
    			/*EDIT LINK END*/	
  • kinda basic and not really tested that much, but this may help some people out getting started:

    https://github.com/erickertz/acf-hidden

  • thanks @erictr1ck! I was just looking for such a field… great timing…

  • To anyone coming here looking for the same as I did: here’s a fork of the @erictr1ck repo. All I did was add an option to set a default value. Since I only needed it for V5 and time was short, it will only work with 5.0+. However, I kept the v4 file from the original repo so go ahead and fork my fork if you want 🙂

    https://github.com/folbert/acf-hidden

  • A solution to set hidden/disabled attribute on a regular field would be helpful when creating front-end forms for submitting data.

    Example:

    Filling an inquiry form for a product, the populated acf_form in the front end can grab current ID from product page and pre fill an ACF Post Object type with it’s current ID.

    Maybe this settings can be available in the acf_form() options arguments when populating the form or via load_field/name={$fieldname} filter

    Somthing like:

    
    
    add_filter('acf/load_field/name=property','wc_set_field');
    function wc_set_field($field){
    		
    		if( !is_admin() && is_single() ){
    			$pid = get_the_ID();
    			$field['default_value'] = $pid;
    			$field['disabled'] = true;
    			$field['hidden'] = true;
    		}
    
    		//same in, same out
    		return $field;	
    }
    

    This way the field value is blocked in the frontend but it can be changed using the regular backend edit screen normally without changing its field type.

    I see myself using ACF a lot to solve front end forms. This feature can help create relations easier.

    Thanks for the great work on ACF.

  • This is marked as solved, but there still is no built-in way to make a field non-editable, right?

  • Wondering the same thing…

  • From what I can see using version 5.4.5 currently I still so no option to disable the field from editing.

  • The only way to do this currently is to use an acf/load_field filter and to set either the readonly or disabled property to true or 1, and this won’t work with all field types, it won’t work on the fields that use Select2. There currently isn’t a way to hide a fields except to add css to the admin_head to hide the field containers.

  • Hi,

    I have found a solution to hide easily a field :

    add_filter( 'acf/load_field/name=inscription_classe', [ $this, 'hide_field' ] );
    
    public function hide_field( $field ) {
    	$field['conditional_logic'] = 1;
    
    	return $field;
    }

    The only problem is : if the field is manually posted with the form (by dom modification or http request modification), the field is saved to the db.

    Not terrible because i don’t want form submitter can change this field. I tried readonly disabled no effect on db saving.

    Always no solution to hide completely a field without the possibility to submit it ?

  • This plugin will completely remove fields from a page based on the users role. https://wordpress.org/plugins/user-role-field-setting-for-acf/. It will not just hide fields and it cannot be used to set fields to read only or disabled. Either a user can edit a field and it is shown or they cannot and the field does not exist. It will also prevent submission of these fields should someone be smart enough to add a field manually that should be removed.

Viewing 25 posts - 1 through 25 (of 31 total)

The topic ‘Feature Request: Hidden / Disabled Field Type’ is closed to new replies.