Create Form

mtiberiu

New Member
Hi , can somebody help me to do a dynamic form like this :

Imagine i have a dron with 3 battery , so i want to make a form to select battery 1 and add how many charge cycles it has , (for example 100) and next time when i open the form, shows me 100 cycles and posibility too add new cycles.
 
Not sure I understand you correct, what you mean with dynamic.
I would create a list/form with two entry fields: battery number and charge cycles. And whenever you open the form in edit mode, you can change the number of cycles.
 
A dropdown with two options : 1 or 2 , when i select one , need to appear a text field to add information
 
You can add element javascript to hide the text field on load and show it for a specific selection - if this is what you mean.
 
Or something like that (for sure can be improved, but this is what I would propose):

Create list1 with elements 'battery' and 'cycles'.

Create list2/form2 with elements 'battery'(dbjoin), 'currentCycles'(calc) and 'newCycles'(field).

Enter in dbjoin (type dropdown) as table 'list1', value = id and label=battery

Enter in currentCycles calculation tab:

$batteryid= (int)'{list2___battery_raw}';
if (is_numeric($batteryid)){
$myDb = \Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$myQuery = $myDb->getQuery(true);
$myQuery
->select('cycles')
->from('list1')
->where('id = ' . $batteryid);
$myDb->setQuery($myQuery);
$currentValue = $myDb->loadResult();
return $currentValue;
}

Add a form2 php-plugin (onBeforeSubmission):

$batterid= (int)'{list2___battery_raw}';
$newCycles = '{list2___newCycles}';
$newValues = new stdClass();
$newValues->id = $batteryid;
$newValues->cycles = $newCycles;
$result = JFactory::getDbo()->updateObject('list1', $newValues, 'id');
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top