Watch the state of a field

Status
Not open for further replies.

madpato

Member
Hello

I need to achieve the following:

I have a text field who stores integer values and i need to "set" somehow if the data entered is an estimate or is a real value, i was thinking on some sort of radio button selection (or dropdown), what i dont know how to achieve is to relate the radio field to the text field, my only guess was to just create the text field and next the radio button with the option, keeping in mind that i should create the state fields with different names:

field 1: ______
state: Option A, Option B, Option C
field 2: ______
state: Option A, Option B, Option C
etc.

Keep in mind that i do not require a repeated group since the fields are a fixed amount.
Any idea on how to approach this? or my thinking is correct? Thanks.
 
I think what you are proposing makes the most sense.

You might consider putting each field and state radiolist in their own group. Then sett the group to use 2 columns, which would then horizontally align both the field and radiolist.
 
Thank you rob, i will try that. Now i have (yet another) question, regarding dates, here is what i need to achieve:

I have a repeating group called "generaciones" which now has a start date and end date and turns out that this is related to other list called "emprendedores" (remember when i was asking about the repeating fields which needed to select year and month?) well now i have to force this to start when the "generacion" starts so if one starts in january 2010 when i go to enter any data on an "emprendedor" (or lets just say it customer so you can understand better) it needs to start on january 2010, i believe this somehow needs to read the data on my start date of the generation, and then show me a date field which starts from there, any idea on how to achieve this?.
Thank you.
 
In general you would need to set the date field to use 'eval' and then in the default area write a php statement to get the related default value. I looked at your site but wasn't able to work out what that query might be.

I have a repeating group called "generaciones"
I presume that's in the 'proyectos' form?

which now has a start date and end date and turns out that this is related to other list called "emprendedores"
How is it related? Which fields would contain the same data so you could tell that a record stored in "proyectos/generaciones" is the same as "emprendedores" ?
 
Hello Rob

Please have a look at this other site called final TNS the other was a sandbox for testing this one has the real data and most of things done on the first are already done here, have a look and let me know.

How is it related? Which fields would contain the same data so you could tell that a record stored in "proyectos/generaciones" is the same as "emprendedores" ?

It is related not by a field but the starting date of the generacion and every customer is related to one of them so, if "customer A" belongs to "generacion 1" and this generacion starts in january 2010 then whenever i enter data for that customer the starting date must be january 2010.
I hope i have made things clearer. Thank you.
 
Hi
We're still struggling to understand this one. Probably as we suck at Spanish! Sorry to re-ask but could you try reformulating your last post using the actual table names and field names? So for example:

A custom (which is stored in the list 'XXX') has a field named 'YYY' - this field contains the generation information.
I want to prefill the generation data into the field 'AAA' in list 'XXX'.

Cheers
Rob
 
Ok no problem, again:

When i create a new generation (stored in generaciones list) I need to give it a start and end date (date field).
When i create or edit a customer (stored in emprendedores list) i must assign it to a generation (via a cascade dropdown) and since that generation has a start and end date, all the dates on the data entered on that customer must be on those ranges. Example:

- I create generation A, with start date january 2010 and end date april 2010.
- I create a customer and then assign him to the generation A
- When i enter sales data (for example, there are other types) to that customer when i set the date of the sale i need to see only the ranges between january 2010 and april 2010 (which was assigned on the generation A).

I hope that makes more sense. Thanks.
 
I really need help on this, since its a very important aspect on my application, please help me, thank you.
 
Thanks the explaination makes things somewhat clearer.
So to recapitulate: you want to limit a date element so that the selected dates are between the generation start and end date for that user?

My next question is what list is the sales data and what element needs to be restricted?
Really if you can try to catch me on the chat widget on http://fabrikar.com tomorrow (gmt 10am to gmt 6pm) we'll try to go through this together to try to sort out your requriements
 
Hello rob

Yes but not for just the user. This is at a generation level option so if the generation has certain date range, anyone who enters data gets that date range.
There are many that i still dont build but right now the repeating group "datos linea base" which points to the list tns_linea_base. If i can see how things are done i can try to carry on alone.
I will try to catch you on the chat so we can move a little faster
 
thanks I've had a go at implementing this for you - the date element 'fecha_inicio_actividades' now has a Advanced->php Allow date function :
I presumed looking at your forms that the generacion was for an entire month
PHP:
$db = JFactory::getDbo();
$input = JFactory::getApplication()->input;
$query = $db->getQuery(true);
 
// Loading the form the generaction data is here
$id = JArrayHelper::getValue($data, 'tns_emprendedores___emp_generacion_raw', 0);
 
// If called via an ajax update then the watch element's value is sent in the property 'v'
$id = $input->get('v', $id);
 
// Query the database to get the start and end dates for the generaciones:
$query->select('fecha_inicio, fecha_termino')->from('tns_generaciones')->where('id = ' . (int) $id);
$db->setQuery($query);
 
$dates = $db->loadObject();
$start = JFactory::getDate($dates->fecha_inicio);
 
// Get the first day of the start month
$start = JFactory::getDate($start->format('Y') . '-' . $start->format('m') . '-01');
 
$end = JFactory::getDate($dates->fecha_termino);
 
// Get the last day of the end month
$end = JFactory::getDate($end->format('Y') . '-' . $end->format('m') . '-' . $end->format('t'));
 
$atEnd = false;
$plusOne = new DateInterval('P1D');
$return = array();
 
// While the start date is less than the end date....
while ($atEnd !== true) {
  $return[] = $start->toISO8601();
  $start->add($plusOne);
  if ($start >= $end)
  {
    $atEnd = true;
  }
}
 
 
return (array) $return;

The code is also run every time the Generaci?n element's value is changed.
 
Thanks rob hats amazing the only detail is that you setted it on the wrong field but i can change that.

Also, (just wondering this serves me greatly) is there a way that we can make this without the page reloading? i assume that would need javascript instead of php code, well that aside the code works great. Thanks!!
 
it should re-run every time a generacion is selected in the form, that's what the 'watch' option is for that I added.
 
Hello Rob

This code is no longer working (dont know why...) and on the first line i am getting an X (which i believe might be the cause of the problem). The element name is: "tns_datos_mensuales_28_repeat___Fecha" and the code is this:

PHP:
$db = JFactory::getDbo();
$input = JFactory::getApplication()->input;
$query = $db->getQuery(true);
 
$id = JArrayHelper::getValue($data, 'tns_datos_mensuales___Generacion_raw', 0);
$id = $input->get('v', $id);
$query->select('fecha_inicio, fecha_termino')->from('tns_generaciones')->where('id = ' . (int) $id);
$db->setQuery($query);
 
$dates = $db->loadObject();
$start = JFactory::getDate($dates->fecha_inicio);
$start = JFactory::getDate($start->format('Y') . '-' . $start->format('m') . '-01');
$end = JFactory::getDate($dates->fecha_termino);
$end = JFactory::getDate($end->format('Y') . '-' . $end->format('m') . '-' . $end->format('t'));
 
$atEnd = false;
$plusOne = new DateInterval('P1D');
$return = array();
 
while ($atEnd !== true) {
  $return[] = $start->toISO8601();  
  $start->add($plusOne);
  if ($start >= $end)
  {
    $atEnd = true;
  }
}
 
return (array) $return;

You can see that field here: http://desarrollo.tilatam.com/tns2/index.php/ingresar-datos-mensuales on the date field on the repeating group. If you select the generation P-2014 it should allow you to select between the 08-2014 and 02-2015 but that is not happening...

THanks.
 

Attachments

  • Capture.PNG
    Capture.PNG
    17.9 KB · Views: 226
I updated from github yesterday that plugin element only and i got an error so i reverted back but it seems i lost that customization you did, it was too late when i realized that (i believed that update would have that function and maybe something else).

EDIT: I have restored the files from a backup i took in the weekend so the plugin remains the same. And maybe this is not working because the date field is in another group, but in the same form. Rob please have a look, Regards
 
seems to be working ok for me, I can see the ajax request being fired and Febuary's dates being returned as the allowed date.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top