Format Lookup Fields

By: Walter Jones | Asked: 08/21/2022
ForumsCategory: General questionsFormat Lookup Fields
Walter JonesWalter Jones asked 2 years ago
How to format look up fields...   So I am working on a photography booking project, and I pretty much have the functionality working great. The issue is the look-up fields I have using are pulling in a date which on the input field is from a date picker.  The lookup data though is 2022-08-11 I want it to read 08-11-2022 or August 11, 2022.   Also, the time field from the input form is a time field with Hr | Min | AM/PM.  The lookup field brings the data in as 24-hour time.  I need to get that back to 12-hour time. Any thoughts?
2 Answers
Best Answer
Walter JonesWalter Jones answered 2 years ago
Just to let everyone know, i was able to solved my issue with this code related to the date field.  
add_filter('frm_validate_field_entry', 'copy_my_field', 10, 3);
function copy_my_field($errors, $posted_field, $posted_value){
    if ( $posted_field->id == 25 ) { //change 25 to the ID of the hidden field to change
        $oDate = $_POST['item_meta'][77]; // change 77 to the ID of your date field
        $_POST['item_meta'][$posted_field->id] =  date("m-d-Y", strtotime($oDate));
    return $errors;
I had to create hidden field on my data input form, and then call the hidden field from my lookup. 

Bobby Clapp answered 2 years ago
Does the lookup data coming in matter? If the date and time fields look correct in the lookup when it is pulleed in, then the "format" parameter of a field ID shortcode that is outputting the data for the lookup field would be all that matters in how you present it.
Walter JonesWalter Jones replied 2 years ago

The lookup fields are the primary fields used by the clients to book the sessions. So the lookup data being display properly is important. When the user goes to select items from the look up fields they are displayed as indicated above.

Bobby Clapp replied 2 years ago

Do you have a page for troubleshooting? It might be a thing that is programmatic and needs to look that way. What we can do then maybe is manipulate your design to make the lookup as it is admin only and then add another field for public view that would format it as desired. Just depends on the workflow.

Walter JonesWalter Jones replied 2 years ago

The form is being loaded on this page. You can see what I mean as you go through it.

Walter JonesWalter Jones replied 2 years ago

Thanks Bobby. It’s not the date picker that’s the issue. It’s how a lookup field translate the data entered by the date picker. The date picker is correct, the look up defaults to YY/MM/DD. That’s what I need to change.

Bobby Clapp replied 2 years ago

That's because of how it's saved to the database from the datepicker field. I expect that if you implement the code above, it will be saved to the database differently and correct your checkbox. Maybe not, but that's how I'm reading it.

Walter JonesWalter Jones replied 2 years ago

Yeah, unfortunately, it didn't make much difference.

Bobby Clapp replied 2 years ago

The jQuery route would be something like this:

getLabel = jQuery('label[for="chkboxfield"]').find('something').text();
labelsplit = getLabel.split('-');

jQuery('label[for="chkboxfield"]').find('something').text(labelsplit[1] + ' - ' + labelsplit[2] + ' - ' + labelsplit[0]');

It gets more complicated if you want to call the date function and try and pull in month names.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community