javascriptangularjsangularjs-directiveangularjs-ng-repeateditablegrid

Angular JS add new row be in editable mode as default


I am creating a grid using the ng-repeat directive, but by clicking on new row , the new row is not in editable mode as a default and user has to click on edit button. how can I make a new row in editable mode ?

    <!-- <tr ng-repeat="primaryskill in primarySkills"> -->
          <tr ng-repeat="skill in skills">
        <td>
          <!-- <span editable-text="primaryskill.name" e-name="name" e-form="rowform"> -->
            <span editable-text="skill.primarySkill.name" e-name="name" e-form="rowform">
            {{ skill.primarySkill.name || 'empty' }}
          </span>
        </td>
        <td >
          <tags-input ng-model="skill.primarySkill.skillGroups" display-property="name" replace-spaces-with-dashes="false" on-tag-added="saveSkillGroup($tag,skill.primarySkill,$index)" on-tag-removed="removeSkillGroup(skill.primarySkill)">
            <auto-complete source="loadskillGroups($query)" display-property="name" load-on-focus="true" min-length="0" load-on-empty="true"></auto-complete>
          </tags-input>
          <!-- <p>Model: {{skill.primarySkill.skillGroups}}</p> -->
        </td>
        <td>
          <tags-input ng-model="skill.secondarySkills"  display-property="name" on-tag-added="saveSecondarySkill($tag,$tag.id, skill.primarySkill)" on-tag-removed="removeSecondarySkill($tag,skill.secondary)">
            <!-- <auto-complete source="loadsecondarySkills($query,skill.primarySkill.id)" display-property="name" min-length="0" load-on-empty="true"></auto-complete> -->
          </tags-input>
          <!-- <p>Model: {{skill.secondarySkills}}</p> -->
        </td>

        <td style="white-space: nowrap;text-align: center;" class="col-xs-12 col-xs-offset-3">
          <!-- form -->
          <form editable-form name="rowform" ng-show="rowform.$visible" class="form-buttons form-inline" onaftersave="savePrimarySkill(skill.primarySkill, $index)">
            <button type="submit" ng-disabled="rowform.$waiting" class="btn btn-primary" >
              save
            </button>
            <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">
              cancel
            </button>
          </form>
          <div >
            <div class="buttons" ng-show="!rowform.$visible">
              <button class="btn btn-primary" ng-click="rowform.$show()">edit</button>
              <button class="btn btn-danger" ng-click="removePrimarySkill(skill.primarySkill)">del</button>
            </div>
          </div>
        </td>
      </tr>
  </table>

  <div id="myprimarySkills">
    <button class="btn btn-default" ng-click="addSkill(primaryskill)">Add Skill</button>
  </div>
</div>

Solution

  • I believe you're using xeditable forms. Just try to add shown="true" on form element.

    Example (just try to replace your form line with this):

    <form editable-form name="rowform" shown="true" ng-show="rowform.$visible" class="form-buttons form-inline" onaftersave="savePrimarySkill(skill, $index)">
    

    Also you can do it via ng-init:

    <form editable-form name="rowform" ng-init="rowform.$show()" ng-show="rowform.$visible" class="form-buttons form-inline" onaftersave="savePrimarySkill(skill, $index)">
    

    Update:

    <form editable-form name="rowform" shown="skill.editable === true" ng-show="rowform.$visible" class="form-buttons form-inline" onaftersave="savePrimarySkill(skill, $index)">
    
    $scope.addSkill = function (someParam) {
     $scope.skills.push({
        editable: true
        //some other staff you're implementing
     });
    }