-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajf.form.dynamic.checkbox.states.inc
More file actions
53 lines (52 loc) · 1.59 KB
/
ajf.form.dynamic.checkbox.states.inc
File metadata and controls
53 lines (52 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
* Uses form states API to conditionally display form fields.
*
* Uses a checkbox field to determine which conditional fields to display.
*/
// Conditionaly display quantity, units, or billed amount fields.
$form['entry_type'] = array(
'#type' => 'checkbox',
'#title' => t('Display Quantity and Unit Cost fields.'),
'#default_value' => FALSE,
);
$form['quantity'] = array(
'#type' => 'textfield',
'#title' => t('Quantity'),
'#default_value' => '1',
'#maxlength' => 9,
'#element_validate' => array('element_validate_number'),
'#description' => t('Enter the number of units sold.'),
'#states' => array(
'visible' => array(
':input[name="entry_type"]' => array('checked' => TRUE)
),
),
);
$form['unit_cost_amt'] = array(
'#type' => 'textfield',
'#title' => t('Unit Cost'),
'#default_value' => '0.00',
'#maxlength' => 12,
'#element_validate' => array('element_validate_number'),
'#description' => t('Enter the cost for one unit.'),
'#states' => array(
'visible' => array(
':input[name="entry_type"]' => array('checked' => TRUE)
),
),
);
$form['billed_amt'] = array(
'#type' => 'textfield',
'#title' => t('Billed Amount'),
'#default_value' => '0.00',
'#maxlength' => 12,
'#element_validate' => array('element_validate_number'),
'#description' => t('Enter the total amount billed for this item.'),
'#states' => array(
'visible' => array(
':input[name="entry_type"]' => array('checked' => FALSE)
),
),
);
// End conditional section.