django date picker input in template - django

I´m trying to use a date picker widget from a model form in the template. I´ve seen several posts but couldn´t get it working correctly.
The one I´m trying now is: Answered question
Form.py
My form code looks like
class FormularioTareas(forms.ModelForm):
class Meta:
model = Tareas
widgets = {'fecha_limite': forms.DateInput(attrs={'class': 'datepicker'})}
fields = ["destinatario", "titulo", "tarea", "resuelto", "fecha_limite"]
Template
In the template I add this script:
/* Include the jquery Ui here */
<script>
$(function() {
$( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
yearRange: "1900:2012",
});
});
</script>
And have this form call in the html
<div style="background: white;">{{ tareas_form.fecha_limite }}</div>
Jquery
I load Jquery as follows and have no problems detected in the browsers console.
<script src="{% static 'js/jquery-3.2.1.min.js' %}"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
What I get
I found out that the picker is working, but the main text box diplays options down when focused so I didn´t see it. The text box is still behaving as a date picker and as a text box. How can I prevent this?
Any clues welcome. Thanks!

I used autocomplete="off" on the form so the usual text input dropdown options don´t show.

Related

Tooltip Dropdown in sharepoint designer / sharepoint 2013 #Beginner

Did you know how to create dropdown with tooltip in sharepoint form?
Could you please suggest me best way to accomplish this functionality.
Thanks.
We can use jQuery code to achieve it, add the code below into a script editor web part in the new/edit form page.
<script src="//code.jquery.com/jquery-1.12.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var fieldname="PC Model Required Field";// modify the fieldname
$("select[title='"+fieldname+"'] option").each(function(){
$(this).attr("title",$(this).val());
});
});
</script>

django-wysiwyg-redactor doesn't work in inlines

So I am using django-wysiwyg-redactor==0.4.9 and Django==1.9.
The issue described here.
I tried a trick in comments, but that didn't help.
Also in browser's console I run this code directly to needed textarea:
$('#id_outboundprogram_set-2-text').trigger('redactor:init');
But anyway there are no redactor on it.
Textarea element looks like this before and after running above code:
<textarea class=" redactor-box" cols="40" data-redactor-options="{"lang": "en", "fileUpload": "/en/redactor/upload/file/", "imageUpload": "/en/redactor/upload/image/", "plugins": ["table", "video"]} id="id_outboundprogram_set-2-text" name="outboundprogram_set-2-text" rows="10"></textarea>
Strange thing is that this code, that I found in jquery.redactor.init.js from package files is not working:
// Initialize Redactor on admin's dynamically-added inline
// formsets.
//
// Credit to the approach taken in django-selectable:
// https://github.com/mlavin/django-selectable
$(document).on('click', '.add-row', function () {
$(this).parents('.inline-related')
.find('tr.form-row:not(.empty-form)').last()
.find('textarea.redactor-box')
.trigger('redactor:init');
});
Any ideas?
UPD:
Well, I still don't know why it happpens, but I solved this problem by including redactor.js file from package files and adding a little changes to above script:
<script type="text/javascript" src="{% static 'js/admin/redactor.js' %}"></script>
var program_tab = $('#outboundprogram_set-group'); // this is just because I have several inlines
program_tab.children('.add-row').on('click', function(){
program_tab.children('.inline-related:not(.empty-form)')
.last()
.find('textarea.redactor-box')
.redactor();
});
UPD 2:
Using this soution there is no plugins and image/file handlers. So I researched a little and found this article.
But image and file handling already implemented in django-wysiwyg-redactor, so I need just to use RedactorUploadView(). Urls can be found in urls.py file from sources. So here is the code:
var program_tab = $('#outboundprogram_set-group');
program_tab.children('.add-row').on('click', function(){
program_tab.children('.inline-related:not(.empty-form)')
.last()
.find('textarea.redactor-box')
.redactor({
imageUpload: "{% url 'redactor_upload_image' 'tours/out/programs/img/' %}",
fileUpload: "{% url 'redactor_upload_file' 'tours/out/programs/files/' %}",
plugins: ['table', 'video', 'fullscreen', 'image']
});
});

Tinymce editor erases html code in admin site

I'm creating content in my pages with some javascript. I'm creating my divs and adding scripts. So, content is pulled into page via javascript.
I'm also using django-tinymce package in my admin site. I'm typing and saving my HTML code via HTML button on tinymce. Everything works fine in template. But, when i want to edit that content, my divs are replaced with an empty div in Tinymce HTML view.
Here is my original html code:
<div site-widget="bulletin">
<bulletin-navigator></bulletin-navigator>
<bulletin-filter-container></bulletin-filter-container>
<bulletin-event-list-container></bulletin-event-list-container>
</div>
<script type="text/javascript" src="http://192.168.30.42:10000/assets/js/common.js"></script>
<script type="text/javascript" src="http://192.168.30.42:10000/assets/js/bulletin.js"></script>
After saving this html code, when i press HTML button on tinymce again i see the following html code:
<div> </div>
<script type="text/javascript" src="http://192.168.30.42:10000/assets/js/common.js"></script>
<script type="text/javascript" src="http://192.168.30.42:10000/assets/js/bulletin.js"></script>
my tincmce config is like this in settings.py file:
TINYMCE_DEFAULT_CONFIG = {
'plugins': "table,paste,searchreplace",
'theme': "advanced",
'cleanup_on_startup': True,
'custom_undo_redo_levels': 10,
'skin' : "o2k7",
'width' : "100%",
'height' : "600px",
'extended_valid_elements': 'div|bulletin-navigator|bulletin-filter-container|bulletin-event-list-container'
}
It looks like TinyMCE is kindly filtering out any tags it does not recognize. It is being overly helpful...
You may need to define 'custom_elements' in TinyMCE - http://www.tinymce.com/wiki.php/Configuration:custom_elements
Spend some time Here and configure it to fit your specific needs.

Tooltip added by DOM manipulation is unable to render HTML

I am attempting to render the HTML in a tooltip, but unfortunately its not working at all.
This is how it has been programmed:
<div class="someField"></div>
<script>
$(function () {
$('.someField').append('(Example)');
$("body").tooltip({html:true,selector: '[data-toggle=tooltip]'});
});
</script>
I have set data-html="true" in the link and furthermore enabled html in the tooltip parameter.
Whats wrong with my code?
UPDATE:
Bootstrap v2.3.1 is used for this project (old framework).
Try this:
$("body").tooltip({ html: true, selector: '[data-toggle="tooltip"]' });
WORKING DEMO

Getting the content rendered inside a #each ember template helper, without the #each content binding

/START description of why
I'm doing a 'load more' type of interaction: user gets at bottom of a page, I load more content.
As I'm using a plugin that formats content in a 'pinterest-style' (masonry), I need to take the output of a rest call, formatted using an ember view, and i'm doing something like:
<div id="list">
</div>
<div id="hidden" style="display:none">
{{#each item in App.itemsController}}
test {{item.id}}
<br />
{{/each}}
</div>
What I want to do is, load the content in the hidden div, and then pass its HTML generated content to the plugin to process in my formatted list view.
If I just copy the #hidden content, the Ember scripts get in, and on subsequent 'load more', content is inserted in the #list, in addition of going in the #hidden div.
That's because I copied the entire handlebars.
So I get rid of the container tag, the one I supposed was wrapping the controller content binding, but even when stripping it from the content I pass to #list, the #list still auto-updates when a 'load more' is called.
I know that's a dirty hackish thing, but in order to improve performance in the client I must take a similar route.
/END description of why
//ACTUAL QUESTION ;)
Given this background, the question is, stripping the container metamorph script tags (like the ones here below), and just take the content inside them, shouldn't get rid of the auto-updating content functionality?
<script id="metamorph-X-start" type="text/x-placeholder"></script>
//ALL THE CONTENT
<script id="metamorph-X-end" type="text/x-placeholder"></script>
Inside those, I just have the actual content generated, like:
<script id="metamorph-9-start" type="text/x-placeholder"></script>
test <script id="metamorph-59-start" type="text/x-placeholder"></script>2873<script id="metamorph-59-end" type="text/x-placeholder"></script>
<br>
<script id="metamorph-9-end" type="text/x-placeholder"></script>
<script id="metamorph-10-start" type="text/x-placeholder"></script>
test <script id="metamorph-60-start" type="text/x-placeholder"></script>2872<script id="metamorph-60-end" type="text/x-placeholder"></script>
<br>
<script id="metamorph-10-end" type="text/x-placeholder"></script>
The alternative is programmatically render the template inside a variable and process that, which is surely a better way of doing this, but I just wonder how the #each binding works internally as I thought the metamorph was doing that.
Have you looked into using a CollectionView and calling the plugin through the didInsertElement callback?
e.g.
MyList = Ember.CollectionView.extend({
itemViewClass: 'App.ListItem',
didInsertElement: function(){
view.$().jqueryPlugin({ ... })
}
})