Support

Account

Home Forums Backend Issues (wp-admin) Generate/Create value of field based on another

Solving

Generate/Create value of field based on another

  • Hi,

    I am trying to do something for a friend in wordpress backend using ACF. I created a custom Post type with fields from ACF. Now I need to be able to display informational text in a label/textbox that is generated based on what the user enters into another text box. Also, this should be non-editable.

    Thoughts??

    Note that this display needs to happen in the backend while a post is being edited.

  • Can someone give me some pointers in this? I can code but am not sure where to start…
    the situation is this.. we have two text fields…field_1 (a text field) and field_2 (a textarea). When a user enters data into field_1, we need to update field_2 with a new string (contains value of field_1). This could be dynamic or on save (what ever is easier).

    Also, field_2 needs to be non-editable so the only way value changes is when field_1 is updated.

  • Well, what you’re looking for is not completely possible with ACF.

    Dynamically updating, meaning the second field changes as data in entered into the first field would need to be done with JavaScript. I can’t really help you with but I can point you to this http://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/

    If you’re okay with then field updating when the post is updated then you can use this filter http://www.advancedcustomfields.com/resources/acfload_value/ and you can adjust the value on the second field by the value of the first.

    Having a field that is not editable is another story entirely. ACF doesn’t currently have a way to set a field as readonly. I would suggest that you take a look at this add on https://wordpress.org/plugins/acf-enhanced-message-field/

  • John – Thank you for the reply. I am attempting to use the JS solution. However, I cannot seem to get the JS to trigger. This is what I have included

    <?php
    function my_acf_input_admin_footer() {
    ?>
    <script type=”text/javascript”>
    (function($) {
    alert(“ready now”);
    })(jQuery);
    </script>
    <?php
    }
    add_action(‘acf/input/admin_footer’, ‘my_acf_input_admin_footer’);
    ?>

    I do not see the alert though. Nor do I see this script when I view source of the page.

    Advice/pointers?

  • I have looked into this, unfortunately like I said above, I’m not too familiar with the JavaScript side of ACF.

    To be completely honest, I would likely to this the hard way. I’d set up a select field that I dynamically load the values for.

    http://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

    Then I’d display the second values, also loaded dynamically and use conditional logic based on what choice was made in the select field.

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

The topic ‘Generate/Create value of field based on another’ is closed to new replies.