[html-formfu] Need help with repeatable field
Ascii King
tech at swattermatter.com
Wed Aug 26 19:25:17 GMT 2009
Jorge Augusto Senger wrote:
> Hi list,
>
> I need some advice regarding repeatable elements. I've the following
> database structure:
>
> Table "clients": cli_id*, cli_name
> Table "clients_tests": cli_id*, tst_id*, tst_result
> Table "tests": tst_id*, tst_name
>
> So, in my clients form, I'd like to have a "tst_result" for each test,
> like this:
>
> Client ID: [ input field for id ]
> Client Name: [ input field for name]
> Test A: [ input field for result ]
> Test B: [ input field for result ]
> Test C: [ input field for result ]
>
> How can I do this configuration using repeatable fields?
You need to set up your has_many relationship between your tables first.
You would need to set up a has_many relationship in your Clients.pm.
__PACKAGE__->has_many(client_tests =>
'MyApp::Schema::Result::ClientTests', 'cli_id');
Then, in your .yml configuration file:
# THECOUNT --
- type: Hidden
name: tests_count
# ** REPEAT CLIENT_TESTS --
- type: Repeatable
nested_name: client_tests
counter_name: tests_count
model_config:
empty_rows: 1 <- Up this number to the number of tests you want
new_rows_max: 100
elements:
# CLI_ID --
- type: Hidden
name: cli_id
# TST_NAME --
- type: Select
name: tst_name
model_config:
resultset: Tests <- name of your tests table
id_column: tst_id
label_column: tst_name
empty_first: 1
# TST_RESULT --
- type: Text
name: tst_result
Hope that helps. I'm a bit of a newb with this, so I hope it is accurate.
More information about the HTML-FormFu
mailing list