File tree 2 files changed +54
-1
lines changed
2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ angular.module('schemaForm')
170
170
// part of the form or schema is chnaged without it being a new instance.
171
171
scope . $on ( 'schemaFormRedraw' , function ( ) {
172
172
var schema = scope . schema ;
173
- var form = scope . initialForm || [ '*' ] ;
173
+ var form = scope . initialForm ? angular . copy ( scope . initialForm ) : [ '*' ] ;
174
174
if ( schema ) {
175
175
render ( schema , form ) ;
176
176
}
Original file line number Diff line number Diff line change @@ -1768,6 +1768,59 @@ describe('directive',function(){
1768
1768
} ) ;
1769
1769
} ) ;
1770
1770
1771
+ it ( 'should redraw form with proper defaults on schemaFormRedraw event' , function ( done ) {
1772
+
1773
+ inject ( function ( $compile , $rootScope ) {
1774
+ var scope = $rootScope . $new ( ) ;
1775
+ scope . person = { } ;
1776
+
1777
+ scope . schema = {
1778
+ type : 'object' ,
1779
+ properties : {
1780
+ name : { type : 'string' }
1781
+ }
1782
+ } ;
1783
+
1784
+ scope . form = [ {
1785
+ key : 'name' ,
1786
+ type : 'text'
1787
+ } ] ;
1788
+
1789
+ scope . options = { formDefaults : { } } ;
1790
+
1791
+ var tmpl = angular . element ( '<form sf-schema="schema" sf-form="form" sf-model="person" sf-options="options"></form>' ) ;
1792
+
1793
+ $compile ( tmpl ) ( scope ) ;
1794
+ $rootScope . $apply ( ) ;
1795
+
1796
+ expect ( tmpl . find ( 'input' ) . attr ( 'disabled' ) ) . to . be . undefined ;
1797
+
1798
+ var disable , enable ;
1799
+ disable = function ( ) {
1800
+ // form element should be disabled
1801
+ scope . options . formDefaults . readonly = true ;
1802
+ scope . $broadcast ( 'schemaFormRedraw' ) ;
1803
+ $rootScope . $apply ( ) ;
1804
+ expect ( tmpl . find ( 'input' ) . attr ( 'disabled' ) ) . eq ( 'disabled' ) ;
1805
+
1806
+ // try to re-enable it by modifying global option
1807
+ setTimeout ( enable , 0 ) ;
1808
+ } ;
1809
+
1810
+ enable = function ( ) {
1811
+ // form element should be back to enabled
1812
+ scope . options . formDefaults . readonly = false ;
1813
+ scope . $broadcast ( 'schemaFormRedraw' ) ;
1814
+ $rootScope . $apply ( ) ;
1815
+ expect ( tmpl . find ( 'input' ) . attr ( 'disabled' ) ) . to . be . undefined ;
1816
+
1817
+ done ( ) ;
1818
+ }
1819
+
1820
+ setTimeout ( disable , 0 ) ;
1821
+ } ) ;
1822
+ } ) ;
1823
+
1771
1824
it ( 'should use supplied template with template field type' , function ( ) {
1772
1825
1773
1826
inject ( function ( $compile , $rootScope ) {
You can’t perform that action at this time.
0 commit comments