nurkka Posted Tuesday at 04:48 PM Share Posted Tuesday at 04:48 PM Hi all! I don't know where to start right now, so I would be grateful for any tips: I need to add a warning message to the first field of a RepeaterMatrix element, indicating when at least one specific other field within the RepeaterMatrix element contains a value. I think the task is not specific to Pro Fields, so I posted it here in general support. Once this first message works, the second task would be to display a warning next to each of the combo field subfields, if the parent field contains a value. In other words, I would need the ability to display warning messages next to fields in the page editor based on the value of other fields. Does anyone know where to start implementing this? Is it only possible with JavaScript or could there be any PW features to do it? Link to comment Share on other sites More sharing options...
Robin S Posted 9 hours ago Share Posted 9 hours ago (edited) You can do something like this: $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { /** @var Inputfield $inputfield */ $inputfield = $event->object; $process = $this->wire()->process; // Return early if this is not ProcessPageEdit if(!$process instanceof ProcessPageEdit) return; // The page being edited $page = $process->getPage(); // The field associated with the inputfield, if any // Useful for when the inputfield is in a repeater, as the inputfield name will have a varying suffix $field = $inputfield->hasField; // The page that the inputfield belongs to // Useful for identifying if the inputfield is in a repeater $inputfield_page = $inputfield->hasPage; // Return early if this is not a page we are targeting if($page->template != 'test_combo') return; // Do some check to identify the inputfield by name or field name if($field && $field->name === 'text_1' && $inputfield_page->template == 'repeater_test_repeater') { // Check some other field value if the message depends on it if($page->test_combo->my_date === '2024-10-18 00:00:00') { // Show an error message $inputfield->error('This is a test error message'); } } // Do some check to identify the inputfield by name or field name if($inputfield->name === 'test_combo_my_date') { // Check some other field value if the message depends on it if($page->test_repeater->first()->text_1 === 'hello') { // Show an error message $inputfield->error('Another test error message'); } } }); Edited 9 hours ago by Robin S Expanded the example 1 Link to comment Share on other sites More sharing options...
nurkka Posted 6 hours ago Author Share Posted 6 hours ago Thanks @Robin S , this is fantastic! I'll try to implement that asap and will report back here 🙂 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now