AngularJS:处理表单 - 存储功能

时间:2015-11-19 20:13:38

标签: javascript angularjs

我有一个用JS编写的非常基本的函数,它存储正在填写的表单数据。

  $scope.storePlatesInspection = function() {

      var procedureId = $scope.selectedProcedure.item.id;
      var plateId = $scope.selectedPlate.item.id;
      var statusCode = $scope.selectedStatus.item.id
      var plateOrientation = $scope.selectedOrientation.item.id;
      var plateQuality = $scope.selectedQuality.item.id;
      var plateContainer = $scope.selectedContainer.item.id;
      var containerSlot = $scope.selectedContainer.item.id;

      $scope.inspectionData = {
        plate_id: plateId,
        document_id: procedureId,
        plate_container_id: plateContainer,
        plate_container_slot: $scope.getSelectedSlotNumber,
        equipment_status_code_id: statusCode,
        orientation_id: plateOrientation,
        plate_quality_id: plateQuality,
        reason: $scope.getSelectedReason
      };
      PlatesInspectionFactory.inspectionUpdate(procedureId, $scope.inspectionData)
        .success(function(data)
        {
          if(!data.success)
          {
            sweetAlert("Oops...", "Something went wrong!", "error");
          }

         $scope.ServerResponse = data;
         sweetAlert('Nailed it!', 'Your entered data was send to database', 'success');

        })
        .error(function(data) {
          console.log(data);
        });

    };

在我的表格中,我有一个开关

  <div class="panel-body">
    <div class="form-group form-group-lg">
      <label class="col-sm-2 control-label">A new Container?</label>
      <div class="col-sm-10">
        <label class="ui-switch ui-switch-lg bg-dark m-t-xs m-r">
          <input ng-model="checked" type="checkbox">
          <i></i>
        </label>
      </div>
    </div>
  </div>
      <div class="panel-body" ng-show="checked">
        <div class="form-group form-group-lg">
          <label class="col-sm-2 control-label">Select a container:</label>
          <div class="col-sm-10">
            <select class="form-control m-t" id="platecontainer" ng-change="getSelectedSlotsInContainer()" ng-model="selectedContainer.item" ng-options="platecontainer as platecontainer.name for platecontainer in plateContainers" ng-required="checked">
              <option value="">Please choose
                <span class="symbol required"></option>
              </select>
            </div>
          </div>
        </div>

        <div class="panel-body">
          <div class="form-group form-group-lg" ng-show="checked">
            <label class="col-sm-2 control-label">Select a slot:</label>
            <div class="col-sm-10">
              <select class="form-control m-t" id="slot-input" ng-model="getSelectedSlotNumber" ng-options="slot for slot in slots" ng-required="checked">
                <option value="">Please choose
                  <span class="symbol required"></option>
                </select>
              </div>
            </div>
          </div>

当用户检查时,下面的字段成为必须。我如何在$scope.inspectionData对象中实现这一目标?

另外,如果你有一个小费让我$scope.storePlatesInspection更好,请随时批评我。

0 个答案:

没有答案