Skip to content

Commit f60dc68

Browse files
committed
Adding FormController
1 parent aa72c9f commit f60dc68

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

src/Angular/FormController.purs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
module Angular.FormController
2+
( FormController(..)
3+
, FormCtrl(..)
4+
, addControl
5+
, removeControl
6+
, setValidity
7+
, setDirty
8+
, setPristine
9+
, pristine
10+
, dirty
11+
, valid
12+
, invalid
13+
, error
14+
) where
15+
16+
import Control.Monad.Eff
17+
18+
import Angular.NgModelController (NgModelController(..), ValidationErrorKey(..))
19+
20+
foreign import data FormController :: *
21+
22+
foreign import data FormCtrl :: !
23+
24+
foreign import addControl
25+
" function addControl(control){ \
26+
\ return function($ctrl){ \
27+
\ return function(){ \
28+
\ return $ctrl.$addControl(control); \
29+
\ }; \
30+
\ }; \
31+
\ } "
32+
:: forall e a. NgModelController a -> FormController -> Eff (ngform :: FormCtrl | e) Unit
33+
34+
foreign import removeControl
35+
" function removeControl(control){ \
36+
\ return function($ctrl){ \
37+
\ return function(){ \
38+
\ return $ctrl.$removeControl(control); \
39+
\ }; \
40+
\ }; \
41+
\ } "
42+
:: forall e a. NgModelController a -> FormController -> Eff (ngform :: FormCtrl | e) Unit
43+
44+
foreign import setValidity
45+
" function setValidity(key){ \
46+
\ return function(isValid){ \
47+
\ return function(control){ \
48+
\ return function($ctrl){ \
49+
\ return function(){ \
50+
\ return $ctrl.$setValidity(key, isValid, control, $ctrl); \
51+
\ }; \
52+
\ }; \
53+
\ }; \
54+
\ }; \
55+
\ } "
56+
:: forall e a. ValidationErrorKey -> Boolean -> NgModelController a -> FormController -> Eff (ngform :: FormCtrl | e) Unit
57+
58+
foreign import setDirty
59+
" function setDirty($ctrl){ \
60+
\ return function(){ \
61+
\ return $ctrl.$setDirty(); \
62+
\ }; \
63+
\ } "
64+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Unit
65+
66+
foreign import setPristine
67+
" function setPristine($ctrl){ \
68+
\ return function(){ \
69+
\ return $ctrl.$setPristine(); \
70+
\ }; \
71+
\ } "
72+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Unit
73+
74+
foreign import pristine
75+
" function pristine($ctrl){ \
76+
\ return function(){ \
77+
\ return $ctrl.$pristine; \
78+
\ }; \
79+
\ } "
80+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Boolean
81+
82+
foreign import dirty
83+
" function dirty($ctrl){ \
84+
\ return function(){ \
85+
\ return $ctrl.$dirty; \
86+
\ }; \
87+
\ } "
88+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Boolean
89+
90+
foreign import valid
91+
" function valid($ctrl){ \
92+
\ return function(){ \
93+
\ return $ctrl.$valid; \
94+
\ }; \
95+
\ } "
96+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Boolean
97+
98+
foreign import invalid
99+
" function invalid($ctrl){ \
100+
\ return function(){ \
101+
\ return $ctrl.$invalid; \
102+
\ }; \
103+
\ } "
104+
:: forall e. FormController -> Eff (ngform :: FormCtrl | e) Boolean
105+
106+
foreign import error
107+
" function error($ctrl){ \
108+
\ return function(){ \
109+
\ return $ctrl.$error; \
110+
\ }; \
111+
\ } "
112+
:: forall e a. FormController -> Eff (ngform :: FormCtrl | e) { | a }

0 commit comments

Comments
 (0)