Jump to content

Juergen

Members
  • Posts

    1,421
  • Joined

  • Last visited

  • Days Won

    18

Everything posted by Juergen

  1. Thanks @Robin S thats true, I need it on change and onload, so its a job for a custom jquery in my adminscripts.js
  2. Hello @ all, I have tried to combine multiple conditions with an OR statement at inputfield dependencies but it doesnt work. condition1=2 OR condition2=1 I havent found anything about this. Has anyone tried to achive the same and found the correct syntax or is this still impossible? Thanks
  3. Thanks @bernhard your solution works pretty well.
  4. Hi there, I use this field type with translateable strings and it works. My problem is I cannot find where I could translate it in the backend. Example: Fieldname: calendarbox PHP code inside this field: The output in the backend works. Maybe I have to create the translateable file manually. Can anyone help me out? Best regards
  5. No its a notice - it only shows up as an error because I am running Tracy in strict mode. These are my settings:
  6. Hello @benbyf can you check the following message: Thanks!
  7. Here is a tipp for you if you want to check for validation errors in inputfields before processing php code inside a Hook function. My goal was to run the code inside the Hook function only if there are no errors after processing the form in the backend. $pages->addHookBefore('saveReady', function($event) { $page = $event->arguments[0]; //count errors during input process $errors = $page->errors('all'); $errors = count($errors); if ($errors == 0) { ......//run your code } }); In this case I run a Hook before "saveReady" inside my ready.php. But I only want to run my php.code inside this Hook function if there are no errors in the form submission. So I need to check for errors in the form submission first. These 3 simple lines of code are necessary: $page = $event->arguments[0]; //count errors during input process $errors = $page->errors('all'); $errors = count($errors); The first step is to define the page variable $page; Second step is to get the error array Last step is to count the entries in the array to get the number of the errors Thats all! Afterwards you can use the number of errors in an if-statement to run the code only if there are no errors. Hope this will be helpful for someone.
      • 6
      • Like
  8. Hello @kongondo thanks for the explanation. I have implemented your first version and it works well, means that it shows the error message at the top bar and next to the field. My previous attempts showed only the error message at the top bar and not next to the field. So using a session is not a problem. I only thought that the same process could be achived with simplier methods. Anyway, it works very well. I think it will be a good feature for PW if every field has a custom validation field in its field settings where you can add additional php code for validation and you will have access to the api variables.
  9. Thanks @kongondo, I will give it a try. To me it seems a bit complex using sessions for this. I guess there will be another way, which works like an $input->post validation, but I am struggeling with this problem for a while. Its also unclear to me why $form->get("date_end"); doesn´t grab the value of the input field "date_end" after form submission Many thanks for your solution.
  10. I took a look at https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module My code is $pages->addHookAfter("ProcessPageEdit::processInput", function($event){ $form = $event->object; $firstdate = $form->get("date_end");//date field 1 $lastdate = $form->get("recurringdateend");//field 2 $this->message("Datum: {$firstdate} "); }); But if I add this to my init.php or ready.php I dont get the value of date field 1 in the message. So it seems that after submission of the form the value will not be grabed. I only put the message line to the code to see if the hook works. I dont know what I should do: I use a hook after, I use processInput which is for processing input data, I use the form as my object and I try to grab the values of the form fields with the get() method - In my opinion this should be the correct way.
  11. Ok, I have read the docs and I put the following code into ready.php $pages->addHookBefore('saveReady', function($event){ $form = $event->object; $page = $event->arguments[0]; if($page->template == "events"){ $lastdate = $page->getUnformatted("recurringdateend"); $firstdate = $page->getUnformatted("date_end"); if($firstdate > $lastdate){ $form->error("First date could not be after the last date."); } } }); The validation works, but: The page will be saved, but it should not because there is an error The error message is not next at the form field. It is only at the top bar. I know that form->error has no relation with the field itself but using fe $form->get("recurringdateend")->error.... doesnt work.
  12. Oh sorry there was a copying mistake. First line must be $pages->addHookAfter("processInput",function($event) { but this doesnt work too.
  13. $form is the form of the current page beeing loaded in the backend.
  14. Hello @ all, I have studied several posts in this forum (fe. https://processwire.com/talk/topic/969-input-validation-in-back-end-fields/?do=findComment&comment=58931), but I am not able to perform a custom validation of one of my input fields Goal: Check if the date of one field is higher than the other, output an error if the condition doesnt match Here is what I have tried so far: $form->addHookAfter("processInput",function($event) { $form = $event->object; $firstdate = $form->get("date_end");//date field 1 $lastdate = $form->get("recurringdateend");// date field 2 if($firstdate >= $lastdate){ //check if the date of field 1 is higher than the value of field 2 $lastdate->error("Last date must be higher than the first date"); } }); I have tried to insert it in init.php and also in ready.php but without success Has somebody tried to achieve something similar and know how to deal with this situation? Best regards
  15. Thanks, I have solved this problem now with another way, where I dont need hooking into the pagetable field, but I will take a look at Inputfield::processInput.
  16. Hello @ all, I have a pagetable field on a page and I want to know if it is possible to check if an item of the pagetable was selected for deletion. As you can see I have clicked the basket icon to delete one item in the pagetable field. What I want to achive is to check fe via a hook before saving the page if an item was activated for deletion, so I can use fe an if/else statement with different code lines. Has anyone done something similar and has an idea how to achive this? Best regards
  17. You are right: Combining was the solution - now it works
  18. As you can see the children were created with an addHookBefore "saveReady" hook //creation of children $pages->addHookBefore('saveReady', function($event) { $page = $event->arguments[0]; ....some code logic foreach ($periods as $key => $item) { // create new page $k = new Page(); $k->template = 'single-event'; // set template // Copy page fields from parent page to newly created child pages $k->title = $page->title; $k->eventtype = $page->eventtype; $k->eventstatus = $page->eventstatus; $k->participantmaxnumber = $page->participantmaxnumber; $k->eventmaxstatus = $page->eventmaxstatus; $k->notifiable = $page->notifiable; ...... $k->save(); } }); This code works! I have shortened the code because at the beginning there were only some date calculations for recurring events. Then in the ready.php I have tried to store the number of the children in the subdatesnumber field. // Add number of subevents to the subeventnumber field $pages->addHookBefore("saved", function($event) { $page = $event->arguments[0]; if ($page->template == 'events') { if (($page->numChildren) > 0) { $page->subdatesnumber = $page->numChildren; } } });
  19. AddHookbefore doesnt work because the number of the children will not be stored. I guess that the children were not created at the time of the Hook, so numChildren doesnt work.
  20. Hello @ all, I need to store the number of children in an integer field in the parent page after the children were created. I use the ready.php for the code: $pages->addHookAfter("saved", function($event) { $page = $event->arguments[0]; if ($page->template == 'events') { if (($page->numChildren) > 0) { $page->subdatesnumber = $page->numChildren; $page->save(); } } }); I always get a blank page after save with this piece of code. I have tried several variations but without success. events = template name of the parent page subdatesnumber = integer field in the parent page where the number of children should be stored (fe 4) Workflow: After saving of the parent page some child pages will be created. After they were created the number of children should be stored in the field "subdatesnumber" which is in the parent page. Does anyone know what could be wrong with the code? Best regards
  21. Great. The fix works!
  22. I can confirm this error too.
  23. Mmhh! Your version seems not to work: $itemnumber = $event->object->getPage()->NAMEOFYOURPAGETABLEFIELD->count(); $this->message("Number of items:{$itemnumber}"); Returns always 0 in the message in my case.
  24. Ok, thanks for the hint. In my case I have only direct children in the page table field, but I have changed it to your snippet.
×
×
  • Create New...