mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-21 05:09:15 +00:00
Disable create profile from signup when submitting
This prevents people re-submitting the form multiple times. Although the backend validates it, we show an ugly alert message that is hard for users to understand.
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
Darkswarm.controller "RegistrationFormCtrl", ($scope, RegistrationService, EnterpriseRegistrationService) ->
|
||||
$scope.submitted = false
|
||||
$scope.isDisabled = false
|
||||
|
||||
$scope.valid = (form) ->
|
||||
$scope.submitted = !form.$valid
|
||||
form.$valid
|
||||
|
||||
$scope.create = (form) ->
|
||||
EnterpriseRegistrationService.create() if $scope.valid(form)
|
||||
$scope.disableButton()
|
||||
EnterpriseRegistrationService.create($scope.enableButton) if $scope.valid(form)
|
||||
|
||||
$scope.update = (nextStep, form) ->
|
||||
EnterpriseRegistrationService.update(nextStep) if $scope.valid(form)
|
||||
|
||||
$scope.selectIfValid = (nextStep, form) ->
|
||||
RegistrationService.select(nextStep) if $scope.valid(form)
|
||||
|
||||
$scope.disableButton = ->
|
||||
$scope.isDisabled = true
|
||||
|
||||
$scope.enableButton = ->
|
||||
$scope.isDisabled = false
|
||||
|
||||
@@ -11,7 +11,7 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService,
|
||||
for key, value of enterpriseAttributes
|
||||
@enterprise[key] = value
|
||||
|
||||
create: =>
|
||||
create: (callback) =>
|
||||
Loading.message = t('creating') + " " + @enterprise.name
|
||||
$http(
|
||||
method: "POST"
|
||||
@@ -25,6 +25,7 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService,
|
||||
@enterprise.id = data
|
||||
EnterpriseImageService.configure(@enterprise)
|
||||
RegistrationService.select('about')
|
||||
callback.call()
|
||||
).error((data) =>
|
||||
Loading.clear()
|
||||
if data?.errors?
|
||||
@@ -32,6 +33,8 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService,
|
||||
alert t('failed_to_create_enterprise') + "\n" + errors.join('\n')
|
||||
else
|
||||
alert(t('failed_to_create_enterprise_unknown'))
|
||||
|
||||
callback.call()
|
||||
)
|
||||
|
||||
update: (step) =>
|
||||
|
||||
@@ -45,4 +45,4 @@
|
||||
.row.buttons
|
||||
.small-12.columns
|
||||
%input.button.secondary{ type: "button", value: "{{'back' | t}}", ng: { click: "select('contact')" } }
|
||||
%input.button.primary.right{ type: "submit", value: "{{'create_profile' | t}}" }
|
||||
%input.button.primary.right{ ng: { disabled: 'isDisabled' }, type: "submit", value: "{{'create_profile' | t}}" }
|
||||
|
||||
Reference in New Issue
Block a user