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:
Pau Perez
2017-09-07 15:59:07 +02:00
parent 86460ffbde
commit 942ab55ddc
3 changed files with 14 additions and 3 deletions

View File

@@ -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

View File

@@ -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) =>

View File

@@ -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}}" }