私のコードにはブール値のチェックボックスがあります。私の認識では、オンチェックではその値を true として返し、チェックを外すとその値を false として返す必要があります。しかし、私は次のような別の状況に直面しています。
ページの初期ロード時に、メッセージが表示されます:「選択されていません」 チェックボックスをオンにすると、値が表示されます:「true」 「true」、何回チェックしたりチェックを外したりしても。
誰かが私に何が問題で、どのように修正して望ましい結果を得ることができるかを教えてもらえますか:
オートフォーム HTML コードは次のとおりです。
{{#autoForm collection='Collections.Category' validation='submit' id='CategoryInsertForm' class="form-horizontal form-with-legend" role="form" type='method' meteormethod='CategoryInsertMethod' }}
{{ currentFieldValue 'isParent' }}
{{> afFormGroup name='isParent' id='isParent' type="boolean-checkbox"}}
{{#if afFieldValueIs name="isParent" value= 'true'}}
{{> afFieldInput name='parentId' id='parentId' class='form-control'}}
{{/if}}
{{/autoForm}}
JSコードは次のとおりです。
Template.registerHelper("currentFieldValue", function (fieldName) {
return AutoForm.getFieldValue( fieldName) || "not selected";
});
スキーマコードは次のとおりです。
Collections.Category = new Mongo.Collection('category');
Schemas.Category = new SimpleSchema({
catId:{
type: String,
optional: true,
unique: true
},
isParent: {
type: Boolean,
optional: true,
defaultValue: false,
// ,allowedValues: [true, false]
label: "Parent category"
},
parentId: {
type: String,
label: "ParentID",
optional: true
},
title: {
type: String,
optional:true
}
});
Collections.Category.attachSchema(Schemas.Category);