@@ -205,8 +205,112 @@ describe('Schema form',function(){
205205
206206 } ) ;
207207
208+
209+ it ( 'should use ng-required on required fields' , function ( ) {
210+
211+ inject ( function ( $compile , $rootScope ) {
212+ var scope = $rootScope . $new ( ) ;
213+ scope . person = { } ;
214+
215+ scope . schema = {
216+ "type" : "object" ,
217+ "required" : [ "name" ] ,
218+ "properties" : {
219+ "name" : { "type" : "string" } ,
220+ "nick" : { "type" : "string" }
221+ }
222+ } ;
223+
224+ scope . form = [ "*" ] ;
225+
226+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
227+
228+ $compile ( tmpl ) ( scope ) ;
229+ $rootScope . $apply ( ) ;
230+
231+ tmpl . children ( ) . length . should . be . equal ( 2 ) ;
232+ tmpl . children ( ) . eq ( 0 ) . is ( 'div.form-group' ) . should . be . true ;
233+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . is ( 'input[type="text"]' ) . should . be . true ;
234+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'required' ) . should . be . equal ( 'required' ) ;
235+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'ng-model' ) . should . be . equal ( 'model.name' ) ;
236+ tmpl . children ( ) . eq ( 1 ) . is ( 'div.form-group' ) . should . be . true ;
237+ tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . length . should . equal ( 1 ) ;
238+ expect ( tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . attr ( 'required' ) ) . to . be . undefined ;
239+ } ) ;
240+ } ) ;
241+
242+ it ( 'should use ng-required on required fields, json schema v3' , function ( ) {
243+
244+ inject ( function ( $compile , $rootScope ) {
245+ var scope = $rootScope . $new ( ) ;
246+ scope . person = { } ;
247+
248+ scope . schema = {
249+ "type" : "object" ,
250+ "properties" : {
251+ "name" : { "type" : "string" , "required" : true } ,
252+ "nick" : { "type" : "string" }
253+ }
254+ } ;
255+
256+ scope . form = [ "*" ] ;
257+
258+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
259+
260+ $compile ( tmpl ) ( scope ) ;
261+ $rootScope . $apply ( ) ;
262+
263+ tmpl . children ( ) . length . should . be . equal ( 2 ) ;
264+ tmpl . children ( ) . eq ( 0 ) . is ( 'div.form-group' ) . should . be . true ;
265+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . is ( 'input[type="text"]' ) . should . be . true ;
266+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'required' ) . should . be . equal ( 'required' ) ;
267+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'ng-model' ) . should . be . equal ( 'model.name' ) ;
268+ tmpl . children ( ) . eq ( 1 ) . is ( 'div.form-group' ) . should . be . true ;
269+ tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . length . should . equal ( 1 ) ;
270+ expect ( tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . attr ( 'required' ) ) . to . be . undefined ;
271+ } ) ;
272+ } ) ;
273+
274+ it ( 'should use ng-required on required fields, form override' , function ( ) {
275+
276+ inject ( function ( $compile , $rootScope ) {
277+ var scope = $rootScope . $new ( ) ;
278+ scope . person = { } ;
279+
280+ scope . schema = {
281+ "type" : "object" ,
282+ "properties" : {
283+ "name" : { "type" : "string" } ,
284+ "nick" : { "type" : "string" }
285+ }
286+ } ;
287+
288+ scope . form = [
289+ { key : 'name' , required : true } ,
290+ 'nick'
291+ ] ;
292+
293+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
294+
295+ $compile ( tmpl ) ( scope ) ;
296+ $rootScope . $apply ( ) ;
297+
298+ tmpl . children ( ) . length . should . be . equal ( 2 ) ;
299+ tmpl . children ( ) . eq ( 0 ) . is ( 'div.form-group' ) . should . be . true ;
300+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . is ( 'input[type="text"]' ) . should . be . true ;
301+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'required' ) . should . be . equal ( 'required' ) ;
302+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'ng-model' ) . should . be . equal ( 'model.name' ) ;
303+ tmpl . children ( ) . eq ( 1 ) . is ( 'div.form-group' ) . should . be . true ;
304+ tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . length . should . equal ( 1 ) ;
305+ expect ( tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . attr ( 'required' ) ) . to . be . undefined ;
306+ } ) ;
307+ } ) ;
308+
309+
310+
208311 } ) ;
209312
313+
210314 describe ( 'decorator directive' , function ( ) {
211315 it ( 'should decorate' , function ( ) {
212316
0 commit comments