11var IdentityProviders = {
2-
3- propertyCount : 0 ,
4- properties : null ,
5-
6- init : function ( propertyCount , properties ) {
7-
8- IdentityProviders . propertyCount = propertyCount ;
9- IdentityProviders . properties = properties ;
10-
11- IdentityProviders . loadProperties ( ) ;
2+ init : function ( ) {
123 IdentityProviders . eventHandlers ( ) ;
134 } ,
145
15- loadProperties : function ( ) {
16- Object . keys ( IdentityProviders . properties ) . forEach ( function ( key ) {
17- $ ( "#property-list" ) . append ( IdentityProviders . propertyTemplate ( key , IdentityProviders . properties [ key ] . name , IdentityProviders . properties [ key ] . value ) ) ;
18- } ) ;
19- } ,
20-
216 eventHandlers : function ( ) {
22-
237 FormMvc . disableEnter ( $ ( '#identity-provider-form' ) ) ;
248
259 $ ( "body" ) . on ( "click" , ".add-property" , function ( e ) {
2610 e . preventDefault ( ) ;
27- var currentPropertyCount = IdentityProviders . propertyCount ;
2811
29- $ ( "#property-list" ) . append ( IdentityProviders . propertyTemplate ( currentPropertyCount , "" , "" ) ) ;
30- IdentityProviders . propertyCount ++ ;
12+ // Determine the current property index based on the number of existing properties
13+ var currentPropertyCount = $ ( "#property-list .property" ) . length ;
14+
15+ // Append new property input fields using the updated count
16+ var resultingProperty = IdentityProviders . propertyTemplate ( currentPropertyCount ) ;
17+
18+ $ ( "#property-list" ) . append ( resultingProperty ) ;
19+
3120 } ) ;
3221
3322 $ ( "body" ) . on ( "click" , ".remove-property" , function ( e ) {
3625 } ) ;
3726 } ,
3827
39- propertyTemplate : function ( propertyIndex , key , value ) {
40- return '<div class="property row mt-1 mb-1">' +
41- ' <div class="col-sm">' +
42- ' <input type="text" required value="' + key + '" class="form-control" id="Properties_' + propertyIndex + '__Name" name="Properties[' + propertyIndex + '].Name" />' +
43- ' <span class="text-danger field-validation-error" data-valmsg-for="Properties[' + propertyIndex + '].Name" data-valmsg-replace="true"></span>' +
44- ' </div>' +
45- ' <div class="col-sm">' +
46- ' <input type="text" required value="' + value + '" class="form-control" id="Properties_' + propertyIndex + '__Value" name="Properties[' + propertyIndex + '].Value" />' +
47- ' <span class="text-danger field-validation-error" data-valmsg-for="Properties[' + propertyIndex + '].Value" data-valmsg-replace="true"></span>' +
48- ' </div>' +
49- ' <div class="col-sm-1 col-xs-1"><span class="remove-property oi oi-trash btn btn-danger"></span></div>' +
28+ propertyTemplate : function ( propertyIndex ) {
29+ return '<div class="property row mt-1 mb-1">' +
30+ '<div class="col-sm">' +
31+ '<input type="text" required value="" class="form-control" id="Properties_' + propertyIndex + '__Name" name="Properties[' + propertyIndex + '].Name" />' +
32+ '<span class="text-danger field-validation-error" data-valmsg-for="Properties[' + propertyIndex + '.Name" data-valmsg-replace="true"></span>' +
33+ '</div>' +
34+ '<div class="col-sm">' +
35+ '<input type="text" required value="" class="form-control" id="Properties_' + propertyIndex + '__Value" name="Properties[' + propertyIndex + '].Value" />' +
36+ '<span class="text-danger field-validation-error" data-valmsg-for="Properties[' + propertyIndex + '.Value" data-valmsg-replace="true"></span>' +
37+ '</div>' +
38+ '<div class="col-sm-1 col-xs-1">' +
39+ '<span class="remove-property oi oi-trash btn btn-danger"></span>' +
40+ '</div>' +
5041 '</div>' ;
5142 }
52-
5343} ;
0 commit comments