別のチェックボックスフィールドを有効にする(trueにする)と、エンティティのEDITビューのdatetimeフィールド値を更新する必要があります。ng-adminフォームの別のフィールドを更新するときにフォームフィールドの値を変更する
NGAフィールド
nga.field('launchDate', 'datetime')
.label('Launch date')
nga.field('active', 'boolean')
.template('<active-game-field field="::field" entity="::entity" game="entry"></active-game-field>')
事は、私が「アクティブ」のテンプレート用に作成されたディレクティブの内側に、私はいくつかのロジックをしなければならない、ということで、そこから私は、フロントエンドの要素の値を変更したいです'launchDate'の
フォームのすべてのフィールドをディレクティブに渡すために、 ':: fields'のような属性を使用するなど、簡単にこれを行う方法はありますか?
今はrequire: '^ form'または ':: entity'を介してフィールドにアクセスできますが、これらの値はフロントエンドフィールドの値ではなくJSONリクエスト/レスポンスに対してのみ変更されます。
ディレクティブ事前に
module.exports = ['ngDialog', function activeGameField(ngDialog) {
return {
require: '^form',
restrict: 'E',
scope: {
'field': '&',
'game': '&',
'entity': '&'
},
link: function (scope, element, attrs, formCtrl) {
scope.updateLaunchDate = function (elem) {
document.activeElement.blur();
if (elem.value == true) {
ngDialog.openConfirm({
template: '\
<p>Do you want to update the launch date of this game to now?</p>\
<div class="ngdialog-buttons">\
<button type="button" class="ngdialog-button ngdialog-button-secondary" ng-click="confirm(false)">No</button>\
<button type="button" class="ngdialog-button ngdialog-button-primary" ng-click="confirm(true)">Yes</button>\
</div>',
showClose: false,
closeByDocument: false
}).then(function (value) {
if (value) {
var date = new Date(Date.now());
scope.game().values.launchDate = date; // JSON value modified properly after clicking on save entity, but not the frontend value. In this callback I would like to do something like\'elem.value = date;' but for the 'launchDate' element instead if 'this' (active checkbox element).
}
});
}
}
},
template:
'<input type="checkbox" ng-model="value" id="active" name="active" class="form-control ng-pristine ng-untouched ng-valid" \
ng-click="updateLaunchDate(this)">'
};
感謝。