How to validate just the value in a key_value pair?

Support General How to validate just the value in a key_value pair?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #43780
    phillcoxonphillcoxon
    Participant

    I've added a key_value field for "Additional costs" to a custom post type. The key is a text description of the cost and the value is a dollar amount. I'd like to validate submitted keys and values separately.

    Selecting validation (for example "Decimals") in the Advanced tab of the Edit Field Group page will validate both the key and value. So it fails because the keys are text.

    Questions:

    1) Is there any way to validate the submitted key and value separately?
    2) Is it possible to validate just the value submitted?

    Thanks so much!

    #43784
    PeterPeter
    Moderator

    Hello Phil,

    I'm afraid that it isn't possible. Both key and value are the field data and you can get the field data, extract the key or value from the array and validate one of them. The submitted data has the format:

    [key_value_crx6rkqqts] => Array
    (
        [0] => Array
            (
                [0] => test key
                [1] => test value
            )
    
    )
    #43787
    phillcoxonphillcoxon
    Participant

    Hi Peter,

    Thank you.

    It looks like I should be able to do it with remove validation. I'll give that a go.

    #43788
    phillcoxonphillcoxon
    Participant

    Hi Peter,

    Are you able to confirm if remote validation will work for key_value fields if multiple key_value pairs have been added?

    Will the remote validation get called on each key_value pair in turn as the user enters data into a pair and then clicks away?

    Thanks in advance!

    #43793
    PeterPeter
    Moderator

    Hello,

    Yes, it will work like that (both questions). Let me know if it does not work.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.