How to map two fields into a single property in React Final Form - react-final-form

In my app, I have two text fields, one for date and one for time. These fields need to map to a single property startTime in my form (of type Date). Is it possible to do this?

Try this: github.com/final-form/final-form-calculate
Example: http://codesandbox.io/s/oq52p6v96y

Related

Active Choices: Single Map backing two single-select dropdowns

I have a set of data that is returned as a single JSON blob that deserializes into a map. The keys of the map should back one dropdown, and the values of each key are an array of strings that, when that key is chosen in the first dropdown, populate the second dropdown. Changing the first dropdown should repopulate the second with the new set of values corresponding to the array that is the value of the new key.
['foo': ['bar','baz'], 'zoo': ['rab','zab']]
The above data should have one dropdown with 'foo' and 'zoo' as choices. When 'foo' is chosen, the other dropdown should have 'bar' and 'baz'. If 'zoo' is chosen, the other dropdown should change to 'rab' and 'zab'.
I don't want to make the API call more than once as it's not a cheap call, but I am having trouble figuring out if it's possible to back two controls with a single map... I know that I can use reactive controls to make one change based on the value in another dynamically, but not how to have both looking at one data structure.
Either I'm missing something silly, or it's not possible. I'm not sure which it is.

Orbeon Form Builder 4.4 - can database services & actions work with repeats?

Say we have a form built in Form Builder that consists of one repeat, containing two controls: a text input (id) and a text output (name). In addition we have a populated database table with two columns, id & name.
This is how the form should behave: the user can add as many rows as needed. In each row, when an ID is entered for a row, a database service is called which looks up name for the given id, and the Name text output is populated on that row.
It's easy to get such a scheme to work if a repeat isn't involved, but with the repeat, it seems that Orbeon doesn't know from which row to get the id parameter value, or to set the returned name value. Any options for accomplishing this that would work in Form Builder?
Apparently the answer is "no" for 4.4 but forthcoming v4.5 should introduce actions that work with repeats (see here and here).

Generating values for dropdown ONLY for 'C' of CRUD

When choosing 'Add' in CRUD, how best to generate a list of choices to pick from a dropdown?
For U/update - just display what's there...
The field contents starts with a letter, followed by five numeric digits:{A-I,K-N,Z}#####
Each letter has a different 'max' value for the numeric part.
So when adding a new record, I'd like to offer a listbox with one of each letter and that letter's highest numeric value + 10.
So, if the max 'A' as A00120, and max 'B' B00030 (etc) the listbox would have A00130 and B00040.. etc
Save the user having to figure out which is 'next' when generating a new record.
? Thanks,
Mark
This time I'll not be able to come up with ready to use solution, but I must say - everything is possible with ATK4. You just have to customize and extend it to fit your needs :)
Speaking about your question above - I guess you have to split it in multiple parts.
First part is about how to show select box on Create and readonly or disabled field on Update. I guess you can make some custom Form field or pin some action to existing Form Field hook. Not sure exactly what's better in this case.
Second one is about data structure. I believe that this field actually should be 2 fields in DB and maybe (only maybe) merged together in ATK model with addExpression() just for user interface needs to display these 2 fields as one field easily in UI. Maybe such concatenated field will be useful also for searching, but definitely not as only one field stored in DB. Imagine how hard it'll be for DB engine to find max value if such field. Store it like type = letter, num = number and then search like SELECT max(num)+10 FROM t WHERE type='A'
Finally Third part is about how to generate this next number. I read your question 3 times and came to conclusion that actually you don't have to show this +10 numeric value in UI at all if it's hardly predefined anyway. Actually that'll not work correctly if this will be multi-user system which I guess it will. Instead just show simple select box with letters {A-I,K-N,Z} and calculate this next value exactly before inserting data in DB. That can be done using models insert hook. This will be much more appropriate solution and will be better for UI and also more stable because calculated in model not incorrectly in UI part.

Delphi grid with a different data type in each row, displayed dynamically

I am trying to create a Delphi grid to allow display and edit in a db grid of data that might have a different data type on each row. I would like to display a specific control for each data type, e.g. when the data type is DateTime, I want to display my custom edit control that allows typing a date in or popping up a calendar.
The data looks something like this:
Name DataType DateValue StringValue BooleanValue
---------------------------------------------------------
A Date 1/1/2007
B String asdf
C Boolean True
...and in the db, this table has a column for each possible type of value. So, there is a BooleanValue column, DateValue, etc.
What I would like to do is display a single 'Value' column in the grid that displays the appropriate edit control depending on what the 'DataType' is for that row. So, the grid should look like :
Name DataType Value
---------------------------
A Date 1/1/2007
B String asdf
C Boolean True
It seems I will need to display a different edit control (to allow the user to edit the Value column) for each row dynamically based on the value of the DataType column. I know there are more advanced grids out there that handle this sort of problem, but the powers that be will not allow anything but what is available out-of-the-box with Delphi.
Any ideas on how to make something like this work?
Personally, I would not go for editing directly inside the TDBGrid in this case, since your Table is not DB normalized (I don't use it in any case actually). I would have used a Calculated field to display the desired value in the grid, And dynamically created the TDBxxxEdits on the form for each field type (How about your own TDBTreeEdit for example, a TDBRichEdit, or a DB Image pickup editor, etc...?).
In case you do want to use your own controls on the TDBGrid, and replace the default TInplaceEdit editor, you can refer the following article: Adding components to a DBGrid, and a related article: Displaying and editing MEMO fiels in Delphi's TDBGrid
Displaying all of the data in the same column is quite easy. You can simply add a calculated string field, and change the value according to what you are storing in that row.
The editing is quite a bit more complicated. If you want to have an in-place editor, you are in for a world of hurt... I've done it, it's a pain, and takes a lot of time. If you want to display a dialog to edit the value, that's much easier. You can add a column objects to the grid and you can setup the column you have attached to the calc field to display a button. When the button is clicked you simply display the editing dialog needed for that row, and commit the edits when the dialog is closed.
There are other ways to get this done, but I would say the above would be the shortest way. Other ways may include custom draw events to display your data in one column, intercept clicks to create your own editor, etc, etc, etc...
after add calculated fields .
Sample:
procedure OnCalculate(DataSet:TDataSet);
begin
case IndexText(DataSet['ValueType'],['Date','String','Boolean']) of
0:DataSet['DateValue']:=StrToDateTime(DataSet['Value']); // also converting
1:DataSet['StringValue']:=DataSet['Value'];
2:DataSet['BooleanValue']:= MatchText(DataSet['Value'],['1','True','T','Y','Yes']);
{etc datatypes}
end;
end;

How to keep track of selections in sequential form

I have what is essentially a form, only the fields depend on the previous selections, and the type of form object aren't always typical form objects.
For example, the first choices are simply in the form of links. It could be a list of teachers, where when you select a teachers name, the classes that teacher teaches is then displayed in a drop-down list. Then once a class is selected, the available dates and time are displayed in a calendar. Once a date/time is selected I need to know all of the selections that were made -- the teacher, the class, and the date and time.
How would you recommend keeping track of these selections? I'm using ajax, and although the form fields are hidden at times, i can still access their values. The one exception is the teacher selection. Since it's just a link, I pass the selected value to a method, but then I've lost the selection. I could store the selection in a hidden field, but is that really the best solution?
Thanks!
I would use a session store on a controller action. Then once it's complete extract all the gathered information.

Resources