Используя Альпака, у меня есть форма, которая работает нормально
Как правильно создать новую форму на том же html объекте?
$(document).ready(function(){
createForm("firstName","First Name","John","string");
});
function changeForm(){
createForm("carType","Car Type","Jeep","string");
}
function createForm(fieldName,fieldLable,fieldVal,fieldType){
$("#field1").alpaca({
"data": {
fieldName: fieldVal
},
"schema": {
"type": "object",
"properties": {
fieldName: {
"type": fieldType,
"title": fieldLable
}
}
}
});
}
<!-- jquery -->
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!-- bootstrap -->
<link type="text/css" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<!-- handlebars -->
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script>
<!-- alpaca -->
<link type="text/css" href="//cdn.jsdelivr.net/npm/alpaca@1.5.27/dist/alpaca/bootstrap/alpaca.min.css" rel="stylesheet" />
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/alpaca@1.5.27/dist/alpaca/bootstrap/alpaca.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>
<div id="field1" ></div>
<button onclick="changeForm()">change form</button>