vitalets / angular-xeditable

Edit in place for AngularJS
http://vitalets.github.io/angular-xeditable
MIT License
1.91k stars 403 forks source link

Single form for create and update - create opens all inputs and update is one by one #578

Closed amodpandey closed 7 years ago

amodpandey commented 7 years ago

I want to create a single form for create and update. When the form opens in create mode I want to show all the inputs editable (like the way when we click on edit). Similarly if I open the form for update (backed by exiting data) I want each input to be individually editable on click. In both cases the Save will update model and call backend API. Is this supported?

Do you have a forum where the authors look into and attend to questions? I did't see reference on the page.

Thank you

ckosloski commented 7 years ago

I don't think this is supported. Maybe you can do something with an ng-if to setup an editable-form for create and then create individual editable elements for edit.

ckosloski commented 7 years ago

@amodpandey did you ever figure out a solution to your problem?

amodpandey commented 7 years ago

I did something similar but not exactly the same. Created a save button that works for create and update. I was happy to keep the create mode with editable links rather than form mode (but I could achieve this as well).

My solution won't work when we disable accessing scope from dom element (done in production)

function validateFormSubmit() {
  var status = true;
  var editables = document.querySelectorAll('[onbeforesave]')
  for (var i = editables.length - 1; i >= 0; i--)
  {
    var scope = angular.element(editables[i]).scope();
    if(scope.$editable.onbeforesave() !== true) {
      scope.$form.$show();
      scope.$form.$submit();
      status = false;
    }
  }
  return status;
}

With above I could achieve

  1. Define validation for individual form element and use them with Submit
  2. Have form save functionality with 'click to edit' ui behavior.
ckosloski commented 7 years ago

OK, thanks for your comment. Did you want to close this issue?

amodpandey commented 7 years ago

sure.

ckosloski commented 7 years ago

@eugef can you close this issue?