2016-05-02 33 views
1

我需要在实体的EDIT视图中更新'datetime'字段值,只要我启用了不同的复选框字段(将其设置为true)即可​​。在更新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)">' 
}; 

在此先感谢。

回答

0

我不喜欢那么多,但最终我直接通过JavaScrit通过ID访问'launchDate'元素并修改元素值来解决这个问题。

document.getElementById("launchDate").value = dateFormat(now, "yyyy-mm-dd HH:MM:ss"); 

我会更喜欢它做虽然角度或ng-admin,但我无法弄清楚这种方法。

相关问题