Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I am working on MVC with angularJS. In which I am generating dynamic HTML controls from angularjs based on database fields.Like
C#
------------------------------------------------
Lable || Type  ||IsRequired || MinLen || MaxLen
------------------------------------------------
Name  || text  ||Yes        || 3      ||10
Mobile|| number||Yes        || 10     ||12
DOB   ||date   ||Yes        || --     ||--
------------------------------------------------

And I am creating controls using javascript function using
document.CreateElement(input);


and checking database values in if else like
JavaScript
if(DatabaseType=="text"){
document.CreateElement(input);
input.type="text";
}else if(DatabaseType=="number"){
document.CreateElement(input);
input.type="number";
}else if(DatabaseType=="date"){
document.CreateElement(input);
input.type="date";
}

and appending those controls to div using

divId.appendChild(input);


like this

But when my values get change then type date gives me a problem

it doesn't allow to enter text or number in that text box

I also used $compile function then also it gives me a problem please suggest me solution


In short I want to change input type dynamically like date to text
but when I do this it doesn't allow.

What I have tried:

JavaScript
if(DatabaseType=="text"){
document.CreateElement(input);
input.type="text";
}else if(DatabaseType=="number"){
document.CreateElement(input);
input.type="number";
}else if(DatabaseType=="date"){
document.CreateElement(input);
input.type="date";
}

divId.appendChild(input);

$compile(divId);
Posted
Updated 11-Feb-17 0:42am
v4

Assuming that you are getting data to generate controls, you can dynamically generate them directly through angularjs. No javascript for createElement is required. You can utilize power of angularjs

<table>
    <tr ng-repeat="d in data">
        <td><input type="d.type" value="d.Lable" minlength="d.minLen" maxlength="d.maxlength"></td>
        
    </tr>
</table>
 
Share this answer
 
use some coding from my blog, that I will share later here
 
Share this answer
 
Comments
Atmesh Sonawane 1-Dec-16 3:26am    
Please give me a specific link
King Fisher 1-Dec-16 4:23am    
you got solution?
Atmesh Sonawane 1-Dec-16 6:57am    
No
King Fisher 1-Dec-16 7:23am    
then,why did you accepted this as solution ?
Atmesh Sonawane 3-Dec-16 3:33am    
Ok, Sorry I didn't know the meaning of Acceptance of answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900