Writing value in hidden mandatory field when saving - possible?

27 views
Skip to first unread message

cardman3000

unread,
Nov 6, 2020, 1:51:42 AM11/6/20
to Joomla Component Builder
I have a field which is conditionally hidden depending on the value of another field. 
It is also defined as a mandatory field via PHP getForm Method:

if(JFactory::getApplication()->isSite() && $form->getValue('type') == "printer") {
$form->setFieldAttribute('status_printer', 'required', 'true');


The field also has no default value. In the scenario when the field is hidden, a value 1 should be written in this field when saving. I use PHP (save method - after data modeling) for this:

 
$data['status_printer'] = 1;


This method writes the value 1 when saving, but only if the field is not defined as required. 


I don't want to define a default value in this field because if it is not hidden the user should enter his own value.  

My general question: is it even possible that the value 1 is written in a hidden mandatory field when saving?

Thanks in advance 

Peter Evgeniev

unread,
Nov 6, 2020, 3:55:30 AM11/6/20
to cardman3000, Joomla Component Builder
Hey Zdravko,

Please try that:

$form->setValue('fieldname', '', 'value');

Let me know if that works for you.

Peter

--
You received this message because you are subscribed to the Google Groups "Joomla Component Builder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcb+uns...@vdm.io.
To view this discussion on the web visit https://groups.google.com/a/vdm.io/d/msgid/jcb/ae64d3bd-8df2-4406-a86a-30d4d642d7ddn%40vdm.io.


--
Warm Regards
Peter Evgeniev
+359 877 876 089
Message has been deleted

cardman3000

unread,
Nov 6, 2020, 11:07:00 AM11/6/20
to Joomla Component Builder, peter.e...@gmail.com, Joomla Component Builder, cardman3000
No, unfortunately not working.
I've tried both save Methods (before and after data modeling).

Regards

cardman3000

unread,
Nov 6, 2020, 1:03:56 PM11/6/20
to Joomla Component Builder, cardman3000, peter.e...@gmail.com, Joomla Component Builder
I have to admit that this idea of ​​mine is bad and not logical: why a mandatory field if a value is definitely written when saving?

An option with conditional dropdown lists would be best: depending on the value in dropdown A, the corresponding selection is offered in dropdown B.
I saw an example in the tutorial "How to filter a list field based on association with another field" (with region and country).

My question: is there a description with these codes in writing format, so that I can understand it better than from the video.

I also try to understand why such a list field with association with another field in Joomla generator is so complicated and for example, in other PHP generators (phpRunner, AppGini ...) something like this can be done in 30 seconds.
 

Please don't get me wrong, I like this tool ... and I'm trying to develop myself further

Peter Evgeniev

unread,
Nov 6, 2020, 4:01:35 PM11/6/20
to cardman3000, Joomla Component Builder
Zdravko, you should stick to your initial plan. The code i sent should be used in the form rendering section. There it will work on loading the form. You can have proper setup with the examples from before. Just play around a bit more.

Peter
Reply all
Reply to author
Forward
0 new messages