Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Proposal) bh-submit directive submission #431

Closed
sfount opened this issue May 25, 2016 · 0 comments
Closed

(Proposal) bh-submit directive submission #431

sfount opened this issue May 25, 2016 · 0 comments

Comments

@sfount
Copy link
Contributor

sfount commented May 25, 2016

The bh-submit directive currently stops all propagation (does not call the submit method) if the form.$invalid flag is set.

The goal of this issue is to find a way to allow controllers to perform tasks if the form is invalid, often revolving around informing the user. For example:

  • Display a danger notification
  • Handle an unrelated error
  • Scroll to the invalid form element

One suggestion for how this could be achieved is to remove the $invalid check from the bh-submit directive - this will always call the submission method and the directive can no longer assume a Promise will be returned.

One way of accomidating this is to check if the required method (finally) is returned in the function call - if not the loading state should simply be reverted.

For example:

FormController.$toggleLoading();

let response = $scope.submit();

if (response.finally) { 
  // attach method to clean up loading state 
  response.finally(() => FromController.$toggleLoading());
} else { 
  // method either did not return or quit early - retract loading state
  FormController.$toggleLoading();
}

Disadvantages:

  • If the controller forgets to return a promise to the loading directive it will simple toggle loading off. This is a programmer mistake but may not be easy to catch

@IMA-WorldHealth/local-contributors This will change the way the submission directive works so should first be approved.

jniles referenced this issue in jniles/bhima May 26, 2016
This commit implements the suggestions proposed in #431.  The `bhSubmit`
directive responsible for toggle the form's $loading state now supports
inputs other than Promises.  If the input is not a promise, the form
immediately cancels the $loading state.  Otherwise, the $loading state
is toggled off on resolution of the Promise.

Closes #431.
jniles referenced this issue in jniles/bhima May 27, 2016
This commit implements the suggestions proposed in #431.  The `bhSubmit`
directive responsible for toggle the form's $loading state now supports
inputs other than Promises.  If the input is not a promise, the form
immediately cancels the $loading state.  Otherwise, the $loading state
is toggled off on resolution of the Promise.

Closes #431.
sfount pushed a commit that referenced this issue May 27, 2016
This commit implements the suggestions proposed in #431.  The `bhSubmit`
directive responsible for toggle the form's $loading state now supports
inputs other than Promises.  If the input is not a promise, the form
immediately cancels the $loading state.  Otherwise, the $loading state
is toggled off on resolution of the Promise.

Closes #431.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant