@@ -205,6 +205,102 @@ describe('Schema form',function(){
205205
206206 } ) ;
207207
208+ it ( 'should use disable readonly input fields, v3 style' , function ( ) {
209+
210+ inject ( function ( $compile , $rootScope ) {
211+ var scope = $rootScope . $new ( ) ;
212+ scope . person = { } ;
213+
214+ scope . schema = {
215+ "type" : "object" ,
216+ "properties" : {
217+ "name" : { "type" : "string" , "readonly" : true } ,
218+ "nick" : { "type" : "string" }
219+ }
220+ } ;
221+
222+ scope . form = [ "*" ] ;
223+
224+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
225+
226+ $compile ( tmpl ) ( scope ) ;
227+ $rootScope . $apply ( ) ;
228+
229+ tmpl . children ( ) . length . should . be . equal ( 2 ) ;
230+ tmpl . children ( ) . eq ( 0 ) . is ( 'div.form-group' ) . should . be . true ;
231+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . is ( 'input[type="text"]' ) . should . be . true ;
232+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'disabled' ) . should . be . equal ( 'disabled' ) ;
233+ tmpl . children ( ) . eq ( 1 ) . is ( 'div.form-group' ) . should . be . true ;
234+ tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . length . should . equal ( 1 ) ;
235+ expect ( tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . attr ( 'disabled' ) ) . to . be . undefined ;
236+ } ) ;
237+ } ) ;
238+
239+ it ( 'should use disable readonly input fields, v4 style' , function ( ) {
240+
241+ inject ( function ( $compile , $rootScope ) {
242+ var scope = $rootScope . $new ( ) ;
243+ scope . person = { } ;
244+
245+ scope . schema = {
246+ "type" : "object" ,
247+ "properties" : {
248+ "name" : { "type" : "string" , "readOnly" : true } ,
249+ "nick" : { "type" : "string" }
250+ }
251+ } ;
252+
253+ scope . form = [ "*" ] ;
254+
255+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
256+
257+ $compile ( tmpl ) ( scope ) ;
258+ $rootScope . $apply ( ) ;
259+
260+ tmpl . children ( ) . length . should . be . equal ( 2 ) ;
261+ tmpl . children ( ) . eq ( 0 ) . is ( 'div.form-group' ) . should . be . true ;
262+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . is ( 'input[type="text"]' ) . should . be . true ;
263+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'disabled' ) . should . be . equal ( 'disabled' ) ;
264+ tmpl . children ( ) . eq ( 1 ) . is ( 'div.form-group' ) . should . be . true ;
265+ tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . length . should . equal ( 1 ) ;
266+ expect ( tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . attr ( 'disabled' ) ) . to . be . undefined ;
267+ } ) ;
268+ } ) ;
269+
270+ it ( 'should use disable readonly input fields, form override' , function ( ) {
271+
272+ inject ( function ( $compile , $rootScope ) {
273+ var scope = $rootScope . $new ( ) ;
274+ scope . person = { } ;
275+
276+ scope . schema = {
277+ "type" : "object" ,
278+ "properties" : {
279+ "name" : { "type" : "string" } ,
280+ "nick" : { "type" : "string" , "readOnly" : true }
281+ }
282+ } ;
283+
284+ scope . form = [
285+ { key : 'name' , readonly : true } ,
286+ { key : 'nick' , readonly : false } ,
287+ ] ;
288+
289+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
290+
291+ $compile ( tmpl ) ( scope ) ;
292+ $rootScope . $apply ( ) ;
293+
294+ tmpl . children ( ) . length . should . be . equal ( 2 ) ;
295+ tmpl . children ( ) . eq ( 0 ) . is ( 'div.form-group' ) . should . be . true ;
296+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . is ( 'input[type="text"]' ) . should . be . true ;
297+ tmpl . children ( ) . eq ( 0 ) . find ( 'input' ) . attr ( 'disabled' ) . should . be . equal ( 'disabled' ) ;
298+ tmpl . children ( ) . eq ( 1 ) . is ( 'div.form-group' ) . should . be . true ;
299+ tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . length . should . equal ( 1 ) ;
300+ expect ( tmpl . children ( ) . eq ( 1 ) . children ( 'input' ) . attr ( 'disabled' ) ) . to . be . undefined ;
301+ } ) ;
302+ } ) ;
303+
208304
209305 it ( 'should use ng-required on required fields' , function ( ) {
210306
@@ -281,13 +377,13 @@ describe('Schema form',function(){
281377 "type" : "object" ,
282378 "properties" : {
283379 "name" : { "type" : "string" } ,
284- "nick" : { "type" : "string" }
380+ "nick" : { "type" : "string" , "required" : true }
285381 }
286382 } ;
287383
288384 scope . form = [
289385 { key : 'name' , required : true } ,
290- 'nick'
386+ { key : 'nick' , required : false } ,
291387 ] ;
292388
293389 var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person"></form>' ) ;
0 commit comments