HTML::FormHandler dynamic fields added client side - perl

I'm using HTML::FormHandler and I would like to have a form that has a dynamic number of form elements. Essentially, I have some inputs that are always present, such as first_name, last_name, and email, but then I have an input, pracitce_area, that I can have many of dynamically (so practice_area1, pracitce_area2, etc). So on the client side I will be using jQuery to dynamically add more practice_area inputs, and I would like for my HTML::FormHandler form to be able to process a dynamic number of these inputs and validate them and put them in the database. The practice_area inputs will be stored in a separate table that will be related with a foreign key to the element of this form, so I would like for HTML::FormHandler to know that these are related and pull out a dynamic number when editing, but also be able to save a dynamic number into the database when saving. Is there a way to handle something like this with HTML::FormHandler? Here's the definition of my form:
package test::Form::Base;
use namespace::autoclean;
use HTML::FormHandler::Moose;
with 'HTML::FormHandler::TraitFor::Model::DBIC';
has title => ( is => 'ro', default => 'Client Information Form');
has '+item_class' => ( default => 'ClientInformationForm' );
has_field 'first_name' => (
type => 'Text',
label => 'First Name',
required => 1,
);
has_field 'last_name' => (
type => 'Text',
label => 'Last Name',
required => 1,
);
has_field 'email' => (
type => 'Email',
label => 'Email',
required => 1,
);
#would like to have this be dynamic in number, and have HTML::FormHandler know
#that it's related with a foreign key when pulling them out of the database
has_field 'practice_area' => (
type => 'TextArea',
);
no HTML::FormHandler::Moose;
__PACKAGE__->meta->make_immutable;
1;

Have you looked at HTML::Formhandler::Repeatable.
You should just be able to use practice_area in your form and have multiple entries. These will just be pulled in an an array(ref) in form processing.

Related

How can I sort a views field created in hook_views_data_alter?

In a custom drupal 9 module I define a new field for a view within hook_views_data_alter(&$data).
$data['node']['node_views_mydata'] = array(
'title' => t('Node Views Mydata'),
'field' => array(
'title' => t('Node views mydata'),
'help' => t('Shows some data in views'),
'id' => 'node_views_mydata',
'sort' => [
'node_views_mydata' => 'default',
],
)
);
I have also defined a field plugin processing text data for this field, and can insert and output the field in views.
Now I would like to make the field sortable. But I can't do that. I always get the error "unknown column". In fact, node_views_data is not a "real" node field, but only created on the fly via the hook.
Is there nevertheless a way to sort by this column?

Creating an Advanced Search field capable of searching multiple module fields

I am currently encountering issues trying to build a custom search field (itself bound to an unused field on a Module) to search two Phone Number fields. The documentation covering modifications of a search field are really poor, but I have the following in place in the module's SearchFields.php
'phone' =>
array (
'query_type' => 'default',
'operator' => '=',
'db_field' =>
array (
0 => 'home_phone_c',
1 => 'work_phone_c',
),
),
The field itself returns no results, so am I missing something that would prevent this from working?
why not you use "sub-query" operator for this? See SearchFields.php inside metadata folder of Account module. You will see entry like following:
'email' =>
array (
'query_type' => 'default',
'operator' => 'subquery',
'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
'db_field' =>
array (
0 => 'id',
),
'vname' => 'LBL_ANY_EMAIL',
),
this will help you to understand the sugar logic of doing it.
You need to designate the correct tables. Try the below code (or use the tables that you're searching):
'phone' =>
array (
'query_type' => 'default',
'operator' => '=',
'db_field' =>
array (
0 => 'accounts_cstm.home_phone_c',
1 => 'accounts_cstm.work_phone_c',
),
),

In suiteCRM how does one get about changing the Address field country and state text fields to be dropdowns?

I am developing a custom suite CRM module however I find the Address field limiting since it uses text fields for country and state fields.
I have tried researching it by following instructions on this site:
https://johndopenotes.wordpress.com/2013/01/08/sugarcrm-change-address-state-and-country-to-dropdown-menu/
However I am stuck at step 5 since my custom module does not have a metadata directory???
Go to /custom/modules/Leads/metadata and update editviewdefs.php. Look for this code:
array (
'name' => 'primary_address_street',
'hideLabel' => true,
'type' => 'Address',
'displayParams' =>
array (
'key' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
),
1 =>
array (
'name' => 'alt_address_street',
'hideLabel' => true,
'type' => 'Address',
'displayParams' =>
array (
'key' => 'alt',
'copy' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
),
and update the type from Address to CustomAddress
array (
'name' => 'primary_address_street',
'hideLabel' => true,
'type' => 'CustomAddress',
'displayParams' =>
array (
'key' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
),
1 =>
array (
'name' => 'alt_address_street',
'hideLabel' => true,
'type' => 'CustomAddress',
'displayParams' =>
array (
'key' => 'alt',
'copy' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
),
Can someone please give me a pointer as to how I can make address field in my custom module dropdowns instead of text fields?
Instead to choosing Address type field you can use combination of multiple fileds. For an example for street address you can use (datatype:textField)
Similarly for city you can add a text filed. Now for state and country you can use dropdown and add dropdown list as per your need
And for zipcode you can use integer / text field as per your requirement.
Now to make state dependend to country you can use custom javascript / jquery in following way
Add a reference to the javascript file you are going to add at the
end of custom/modules/<>/metadata/[edit|detail]viewdefs.php
$viewdefs['Opportunities']['EditView']['templateMeta']['includes'] = array ( array ( 'file' => 'path/to/file/filename.js', ), );
Add the javascript file you want to include into the location you
referenced above.
Quick Repair from the admin section, then browser refresh
It should just be a case of updating the vardefs for the field so the type is set to enum and the options point to your dropdown list. Then run a repair and rebuild.
The guide you've linked to looks like it is creating a new field type, which I think is overkill. It's also using Sugar logic to make the 2 lists dependent, but I'm not sure that's a feature in SuiteCRM.

HTML::FormHandler access to form field

Is there any way to access the value of form field 'wklloc_id' in the form field options method of field 'prg_id'?
My Form contains (amongst others) these fields:
has_field 'wklloc_id' => ( type => 'Select', label => 'Winkel(locatie)' );
has_field 'prg_id' => ( type => 'Select', empty_select => 'Kies eerst een Winkel(locatie)', label => 'Productgroep' );
At this point my options method for field 'prg_id' contains:
sub options_prg_id
{
my ($self) = shift;
my (#prg_select_list,$productgroep,$productgroepen);
return unless ($self->schema);
$productgroepen = $self->schema->resultset( 'WinkelLocatieProductgroepen' )->search( {}, { bind => [ 2 ] } );
Is is possible to set the value of the bind variable (i.e. 2) to the value of field 'wklloc_id' and how does one do that? Mind you this is needed before any submit.
The value of a select field is set the same way as other fields, i.e. it comes from an init_object, from parameter values, or from a default. For your case, if you want this field to start with the 'value' 2, then just put: default => 2 in your field definition.

Duplicate Validation on Combined Fields in zend form

Hi there I have a table in which combination of three fields is unique. I want to put the check of duplication on this combination. Table looks like
I know how to validate single field, But how to validate the combination is not know. To validate one field I use the following function
public function isValid($data) {
// Options for name field validation
$options = array(
'adapter' => Zend_Db_Table::getDefaultAdapter(),
'table' => 'currencies',
'field' => 'name',
'message'=> ('this currency name already exists in our DB'),
);
// Exclude if a id is given (edit action)
if (isset($data['id'])) {
$options['exclude'] = array('field' => 'id', 'value' => $data['id']);
}
// Validate that name is not already in use
$this->getElement('name')
->addValidator('Db_NoRecordExists', false, $options
);
return parent::isValid($data);
}
Will any body guide me how can I validate duplication on combined fields?
There is no ready to use validator for this, as far as I know. You have either to write your own, or do a check with SQL-query with three conditions (one for each field).
you have to Apply a validation on name element of zend form.
Here is code for add validation on name field.
$name->addValidator(
'Db_NoRecordExists',
true,
array(
'table' => 'currencies',
'field' => 'name',
'messages' => array( "recordFound" => "This Currency Name already exists in our DB") ,
)
);
And you must set required true.