DisabledIF - MFORM fields - moodle

Moodle V2.9
// Enrolment duration
$mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'enrol_self'), array('optional' => true, 'defaultunit' => 86400));
$mform->addHelpButton('enrolperiod', 'enrolperiod', 'enrol_self');
// Notify before enrolment expires
$options = array(0 => get_string('no'), 1 => get_string('expirynotifyenroller', 'core_enrol'), 2 => get_string('expirynotifyall', 'core_enrol'));
$mform->addElement('select', 'expirynotify', get_string('expirynotify', 'core_enrol'), $options);
$mform->addHelpButton('expirynotify', 'expirynotify', 'core_enrol');
$mform->disabledIf('expirynotify', 'enrolperiod');
Enrolment duration has a default enable checkbox.
I wanted to enable Notify before enrolment expires unless enrolment duration is enabled.

The duration field is a group of fields
A text field named number
A select field named timeunit
A checkbox field named enabled
See /lib/form/duration.php
So maybe try
$mform->disabledIf('expirynotify', 'enrolperiod[enabled]', 'notchecked');

Related

Contact Form 7 - how to add several number fields dynamically

I am currently working on a web project where users should be able to have a list of brochures (list comes from custom post type) and enter the amount they would like to order individually for each of them via a simple contact form. My idea was to generate a dynamic list of number fields with the 'wpcf7_form_tag_data_option' hook like in this article:
Dynamicly populate Contact form 7 input fields with current user info when logged in in Wordpress website
So if i am using the select or checkbox field type within contact form 7:
[select anzahlKataloge data:brochures]
or
[checkbox anzahlKataloge data:brochures]
and functions.php:
add_filter('wpcf7_form_tag_data_option', function($n, $options, $args) {
if (in_array('brochures', $options)){
$query = new WP_Query(
array( 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '100', 'post_type' => 'prospekte')
);
while($query->have_posts()) : $query->the_post();
$title = get_the_title();
$brochures[] = $title;
endwhile;
return $brochures;
}
return $n;
}, 10, 3);
It generates the select or checkbox list just fine but i would actually need it to work with the number field type:
[number anzahlKataloge data:brochures]
or with text type:
[text anzahlKataloge data:brochures]
Any help is much appreciated.
Best Regards,
Rafael

Populating a field when choosing a relate field _ suite crm

i'm using suite crm 7.7.5
when i create an opportunity and i choose an account from a relate field, i want a field (country) to be auto populated with the value of the country of the account chosen.
for this, i tried to add the code
$dictionary['Opportunity']['fields']['country_c']['populate_list']= array('id','name','country_c');
$dictionary['Opportunity']['fields']['country_c']['field_list'] = array('account_id_c','account_name','country_c');
in the file \custom\Extension\modules\Opportunities\Ext\Vardefs\sugarfield_country_c.php
knowing that country_c is the name of the column country in the table accounts and the second country_c is the id of the field country in the layout opportunity
but that doesn't work, could someone help me to figure out the reason?
PS : i've tried to follow this tutorial https://developer.sugarcrm.com/2011/08/31/howto-using-a-relate-field-to-populate-a-custom-field/
Here is the extension on #Bozic solution.
If someone is trying to autopopulate related fields based on selection then here is the solution. (Those who are facing "No match for field: Account Name")
Scenario: I have Account Owner (relate to User module) field in Accounts module. And in Cases module I am fetching Account owner fields based on Account selection.
In /custom/modules/Cases/metadata/editviewdefs.php
0 => array(
'name'=>'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_name',
'assigned_user_name' => 'account_owner_case_c',
'assigned_user_id' => 'user_id2_c',
),
),
),
Note:
assigned_user_name is field id of Account owner from Accounts module
assigned_user_id is id field of Account owner
account_owner_case_cis field of Case Account Owner from Case module
account_name is selection field from case module (on selection of this field account owner will get populate)
You should go to custom/modules/{YOUR MODULE}/metadata/editviewdefs.php and edit editviewdefs.php file.First you need to find array in which your relate field(account_name) is defined. It will look similar to this, maybe with some more parameters.
array (
'name' => 'account_name',
),
Now you need to map data from relate field(country_c) to new field(lets say populated_country_c). After editing your array will look something like this.
array (
'name' => 'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_id_c',
'name'=>'account_name',
'country_c' => 'populated_country_c',
),
),
),
Now populated_country_c is the new field in which the data about country will be populated when you choose account in the relate field. So we also need to create that new field. You can do it through studio or manually just by adding new array. Finally your file will look like this
array (
'name' => 'account_name',
'displayParams' => array (
'field_to_name_array' => array(
'id'=>'account_id_c',
'name'=>'account_name',
'country_c' => 'populated_country_c',
),
),
),
array (
'name' => 'populated_country_c',
'label'=> 'LBL_POPULATED_COUNTRY'
),
Now when choosing new account from relate field, populated_country_c will be populated with country_c field from selected account.
Use field billing_account_country rather than country_c, and also use account_id with account_name. The name and the id have to coincide to the same table, I believe.

How to submit the value of a disabled form field?

This page actually a preview where user can't change anything,that he has given before.I have tried bellow code,
echo $this->Form->input('exchange_type', array(
'disabled' => 'disabled',
'empty' => '--Please Select--',
'options' => array(
'6' => 'POINT_TO_PRODUCT',
'7' => 'POINT_TO_GIFT',
'2' => 'POINT_TO_GAME'
)
));
Here field has disabled but it's sending null value to database.I am trying to send actual value that user has been selected.How can I do this ?
That's how HTML works, values of disabled elements are not being sent.
What you can do is using a hidden field, that's what the form helper automatically does when using for example checkboxes, in order to ensure that there's always a value being sent, as unchecked checkboxes do not submit any value, just like disabled inputs.
The hidden field should have the same name as the actual field, and it should be placed before the actual field, that way the hidden value will only be sent in case the following element is disabled.
echo $this->Form->hidden('exchange_type');
echo $this->Form->input('exchange_type', array(
'disabled' => true,
// ...
));
That would pick up the previously POSTed value for both the hidden input and the select input, and the hidden input would be submittable.
See also Cookbook > Helpers > FormHelper > FormHelper::hidden()

How to disable filter of a field in Zend Framework 2 in the controller?

Form to add/edit user I get from service manager with already installed filter, which is the test password. But this password is not needed when the user is edited. Can I somehow disabled password field validation in the controller?
In the getServiceConfig function of the module:
// ....
'UserCRUDFilter' => function($sm)
{
return new \Users\Form\UserCRUDFilter();
},
'UserCRUDForm' => function($sm, $param, $param1)
{
$form = new \Users\Form\UserCRUDForm();
$form->setInputFilter($sm->get('UserCRUDFilter'));
return $form;
},
// ....
In the controller I first of all getting a form object from service manager:
$form = $this->getServiceLocator()->get('UserCRUDForm');
Then disable user password validation and requirements, when user is edited and password not specified:
if ($user_id > 0 && $this->request->getPost('password') == '') {
$form->.... // Someway gained access to the filter class and change the password field validation
}
And after this i make a validation:
$form->isValid();
I found it!
// If user is editted - clear password requirement
if ($user_id > 0) {
$form->getInputFilter()->get('password')->setRequired(false);
$form->getInputFilter()->get('confirm_password')->setRequired(false);
}
This lines is disables requirement of input form fields :)
if you like to set all validators by yourself, call inside your form class
$this->setUseInputFilterDefaults(false);
to disable auto element validations/filter added from zend.
if you like to remove filter from elements call in your controller after your form object this
$form->getInputFilter()->remove('InputFilterName');
$form->get('password')->removeValidator('VALIDATOR_NAME'); should do the trick.
Note that you may have to iterate trough the Validatorchain when using Fieldsets.
$inputFilter->add(array(
'name' => 'password',
'required' => true,
'allow_empty' => true,
));
And on ModeleTable: saveModule:
public function saveAlbum(Album $album)
{
$data = array(
'name' => $album->name,
);
if (isset($album->password)){
$data['password'] = $album->password;
}

SugarCRM filter search result by custom field from current user account

I have the custom field "country_id_c" in both "User" and "CustomModule", I need to limit the user to see only lines from his region (filtering it by country_id_c).
There are two search forms:
when you see the search result of CustomModule from menu
when you add CustomModule as a relationship to other module by using
picker (pop up window).
I found how to filter the result in 1 case with hard-coded value:
file: custom/modules/CustomModule/metadata/SearchFields.php
$searchFields['CustomModule'] = array (
...
'country_id_c' =>
array (
'query_type' => 'format',
'operator' => '=',
'value' => 'Argentina',
'db_field'=>array('country_id_c',)
),
...
what I'm missing here is how to get the current logged-in user's country_id_c. And how to do the same for the (2) search form.
You can access the value by adding:
globals $current_user;
$current_user->country_id_c