Adding input validation to welcome page

This commit is contained in:
Rob Harrington
2014-10-23 14:23:50 +11:00
parent 7d9c5f9e2c
commit 77c0e36ed6
2 changed files with 16 additions and 4 deletions

View File

@@ -1,3 +1,11 @@
angular.module("admin.welcome")
.controller "welcomeCtrl", ($scope) ->
$scope.sells = "unspecified"
$scope.sells = "unspecified"
$scope.submitted = false
$scope.valid = (form) ->
$scope.submitted = !form.$valid
form.$valid
$scope.submit = (form) ->
event.preventDefault() unless $scope.valid(form)

View File

@@ -10,8 +10,9 @@
%br/
the Open Food Network
%form{ name: :sells, method: :put, action: main_app.set_sells_admin_enterprise_path(@enterprise) }
%input{ type: "hidden", id: "sells", name: "sells", ng: { value: "sells" } }
= form_for @enterprise, url: main_app.set_sells_admin_enterprise_path(@enterprise), novalidate: true do |enterprise_form|
-# Have to use hidden:'true' on this input rather than type:'hidden' as the latter seems to break ngPattern and therefore validation
%input{ hidden: "true", id: "sells", name: "sells", ng: { required: true, pattern: "/^(none|own)$/", model: 'sells', value: "sells"} }
.options.sixteen.columns.alpha
- if @enterprise.is_primary_producer
.basic_producer.option.one-third.column.alpha
@@ -60,4 +61,7 @@
// Coming soon - Full Hub
// Email us if you want this option
%input{ type: 'submit' }
.sixteen.columns.alpha
%span.error{ ng: { show: "(enterprise.sells.$error.pattern || enterprise.sells.$error.pattern) && submitted" } }
Please select an option
%input{ type: 'submit', ng: { click: "submit(enterprise)" } }