Skip to content

Commit f2eb869

Browse files
committed
Add nullLabel option
1 parent 007b32d commit f2eb869

File tree

9 files changed

+40
-11
lines changed

9 files changed

+40
-11
lines changed

.versions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
aldeed:autoform@5.4.1
1+
aldeed:autoform@5.5.0
22
33
44
@@ -16,7 +16,7 @@ [email protected]
1616
1717
1818
19-
local-test:aldeed:autoform@5.4.1
19+
local-test:aldeed:autoform@5.5.0
2020
2121
2222

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ forms with automatic insert and update events, and automatic reactive validation
66

77
## Change Log
88

9+
### 5.5.0
10+
11+
For `boolean-radios` and `boolean-select` input types, you can now use the `nullLabel` attribute to specify a label (e.g., "None") for when the value is not set (or to unset it). For backwards compatibility, the `boolean-radios` type will not render a radio element for unsetting unless you set `nullLabel`.
12+
913
### 5.4.1
1014

11-
* Fix `AutoForm.getFieldValue` so that it reacts properly when first called outside of the form, before the form has been rendered. Also attempt to limit unnecessary reruns.
15+
Fix `AutoForm.getFieldValue` so that it reacts properly when first called outside of the form, before the form has been rendered. Also attempt to limit unnecessary reruns.
1216

1317
### 5.4.0
1418

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ If you don't include a `type` attribute, the following logic is used to automati
451451
* Otherwise if the schema type is `String` and you include the `rows` attribute, a `textarea` is used.
452452
* Otherwise if the schema type is `Number`, a `number` type is used.
453453
* Otherwise if the schema type is `Date`, a `date` type is used.
454-
* Otherwise if the schema type is `Boolean`, the `boolean-checkbox` type is used. You may want to specify a `type` of `boolean-radios` or `boolean-select` instead. If you do so, use the `trueLabel` and `falseLabel` attributes to set the labels used in the radio or select control.
454+
* Otherwise if the schema type is `Boolean`, the `boolean-checkbox` type is used. You may want to specify a `type` of `boolean-radios` or `boolean-select` instead. If you do so, use the `trueLabel`, `falseLabel`, and `nullLabel` attributes to set the labels used in the radio or select control.
455455
* Otherwise a `text` type is used.
456456

457457
The following attributes are recognized:
@@ -473,6 +473,7 @@ to `true` to render radios or checkboxes for the `options` instead of `select`.
473473
option for an input with type `boolean-select` or `boolean-radios`.
474474
* `falseLabel`: Set to the string that should be used as the label for the `false`
475475
option for an input with type `boolean-select` or `boolean-radios`.
476+
* `nullLabel`: Set to the string that should be used as the label for the empty value option for an input with type `boolean-select` or `boolean-radios`.
476477
* `value`: Set a specific, potentially reactive, value for the input. If you have also provided a `doc` attribute on the `autoForm` or `quickForm`, this value will override the value from the `doc` object.
477478
* `defaultValue`: Set a reactive default value for the input. If you have also provided a `doc` attribute on the `autoForm` or `quickForm`, this value will be used only when the `doc` object has no value for this field. This takes precedence over the `defaultValue` property of the field's schema. (Also, `defaultValue` from the schema is slightly different in that it is never used if you provide a `doc` attribute.)
478479
* Any additional attributes are passed along to the generated DOM element, meaning that you can add `class`, etc. When providing a boolean attribute, set it to `true` (no quotation marks) or a helper that returns `true`.

inputTypes/boolean-radios/boolean-radios.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66
<div>
77
<label><input type="radio" value="true" name="{{this.name}}" {{trueAtts}} /> {{#with this.atts.trueLabel}}{{this}}{{else}}True{{/with}}</label>
88
</div>
9+
{{#with this.atts.nullLabel}}
10+
<div>
11+
<label><input type="radio" value="" name="{{../name}}" {{nullAtts}} /> {{this}}</label>
12+
</div>
13+
{{/with}}
914
</div>
1015
</template>

inputTypes/boolean-radios/boolean-radios.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,26 @@ AutoForm.addInputType("boolean-radios", {
4545

4646
Template["afBooleanRadioGroup"].helpers({
4747
falseAtts: function falseAtts() {
48-
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'data-schema-key');
48+
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'nullLabel', 'data-schema-key');
4949
if (this.value === false) {
5050
atts.checked = "";
5151
}
5252
return atts;
5353
},
5454
trueAtts: function trueAtts() {
55-
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'data-schema-key');
55+
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'nullLabel', 'data-schema-key');
5656
if (this.value === true) {
5757
atts.checked = "";
5858
}
5959
return atts;
6060
},
61+
nullAtts: function nullAtts() {
62+
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'nullLabel', 'data-schema-key');
63+
if (this.value !== true && this.value !== false) {
64+
atts.checked = "";
65+
}
66+
return atts;
67+
},
6168
dsk: function () {
6269
return {'data-schema-key': this.atts['data-schema-key']};
6370
}

inputTypes/boolean-select/boolean-select.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ AutoForm.addInputType("boolean-select", {
4343
}
4444
},
4545
contextAdjust: function (context) {
46-
var atts = _.omit(context.atts, 'trueLabel', 'falseLabel', 'firstOption');
46+
var atts = _.omit(context.atts, 'trueLabel', 'falseLabel', 'nullLabel', 'firstOption');
4747

4848
// build items list
4949
context.items = [
@@ -55,7 +55,7 @@ AutoForm.addInputType("boolean-select", {
5555
// See https://github.com/meteor/meteor/issues/2174
5656
_id: "",
5757
selected: (context.value !== false && context.value !== true),
58-
label: context.atts.firstOption || "(Select One)",
58+
label: context.atts.nullLabel || context.atts.firstOption || "(Select One)",
5959
atts: atts
6060
},
6161
{

package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package.describe({
22
name: "aldeed:autoform",
33
summary: "Easily create forms with automatic insert and update, and automatic reactive validation.",
44
git: "https://github.com/aldeed/meteor-autoform.git",
5-
version: "5.4.1"
5+
version: "5.5.0"
66
});
77

88
Package.onUse(function(api) {

templates/bootstrap3/inputTypes/boolean-radios/boolean-radios.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
66
<div class="radio">
77
<label><input type="radio" value="true" name="{{this.name}}" {{trueAtts}} /> {{#with this.atts.trueLabel}}{{this}}{{else}}True{{/with}}</label>
88
</div>
9+
{{#with this.atts.nullLabel}}
10+
<div class="radio">
11+
<label><input type="radio" value="" name="{{../name}}" {{nullAtts}} /> {{this}}</label>
12+
</div>
13+
{{/with}}
914
</div>
1015
</template>

templates/bootstrap3/inputTypes/boolean-radios/boolean-radios.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
Template.afBooleanRadioGroup_bootstrap3.helpers({
22
falseAtts: function falseAtts() {
3-
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'data-schema-key');
3+
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'nullLabel', 'data-schema-key');
44
if (this.value === false) {
55
atts.checked = "";
66
}
77
return atts;
88
},
99
trueAtts: function trueAtts() {
10-
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'data-schema-key');
10+
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'nullLabel', 'data-schema-key');
1111
if (this.value === true) {
1212
atts.checked = "";
1313
}
1414
return atts;
1515
},
16+
nullAtts: function nullAtts() {
17+
var atts = _.omit(this.atts, 'trueLabel', 'falseLabel', 'nullLabel', 'data-schema-key');
18+
if (this.value !== true && this.value !== false) {
19+
atts.checked = "";
20+
}
21+
return atts;
22+
},
1623
dsk: function () {
1724
return {'data-schema-key': this.atts['data-schema-key']};
1825
}

0 commit comments

Comments
 (0)