I have the following snippet of code which gives me unterminated string literal error
$(function() {
$('#addDropdown').click(function() {
var $d = $('{{ form |bootstrap }}').fadeIn().delay(1000);
$('#dropdownContainer').append($d);
});
});
I have looked unterminated string literal question and found that it is because multiline problem.My {{ form |bootstrap }} has multiple lines of code as mentioned in the question.So how do I handle the problem
I have the following snippet of code which gives me unterminated string literal error
$(function() {
$('#addDropdown').click(function() {
var $d = $('{{ form |bootstrap }}').fadeIn().delay(1000);
$('#dropdownContainer').append($d);
});
});
I have looked unterminated string literal question and found that it is because multiline problem.My {{ form |bootstrap }} has multiple lines of code as mentioned in the question.So how do I handle the problem
Share Improve this question edited May 23, 2017 at 12:01 CommunityBot 11 silver badge asked Jun 18, 2014 at 11:25 iLoveCamelCaseiLoveCamelCase 47010 silver badges21 bronze badges 3- add }); at the end of code as this is to close your $(function(){ – Bhushan Kawadkar Commented Jun 18, 2014 at 11:26
-
I think you want to render the form somewhere else than in the javascript and then just find it via some class/id selector and call
fadeIn()
on the found element – yedpodtrzitko Commented Jun 18, 2014 at 11:28 - I want to add multiple(unknown number given by user by button clicks) forms to a div.Each form contains a dropdown.Fade in is just to show the transition of adding the element smoothly. – iLoveCamelCase Commented Jun 18, 2014 at 11:31
1 Answer
Reset to default 10In general, to use with JavaScript, you should use |escapejs
filter:
var $d = $('{{ value|escapejs }}');
However, as a matter of best practice you'd better put {{ form|bootstrap }}
in HTML, and use JavaScript just to fade in:
<div id="djangoForm" style="display:none">{{ form|bootstrap }}</div>
<script>
$('#addDropdown').click(function() {
$('#dropdownContainer').append($('#djangoForm'));
}
</script>