JavaScript: True form reset for hidden fields
Seems the easiest way of doing that is having <input style=”display: none” type=”text”/> field instead of <input type=”hidden”/> field. At this case default reset process regularly.
Seems the easiest way of doing that is having <input style=”display: none” type=”text”/> field instead of <input type=”hidden”/> field. At this case default reset process regularly.
With the following CSS: textarea { vertical-align: top; } jsFiddle Demo vertical-align on MDN: The vertical-align CSS property specifies the vertical alignment of an inline or table-cell element. What is Vertical Align? on CSS-Tricks
Try this: document.getElementById(’email’).onkeydown = function(e){ if(e.keyCode == 13){ // submit } };
for those looking to incorporate this feature, I’ve taken a new approach from the model end of things. Being that all fields are required to be filled out in order for the user to submit and not receive an error alert, I gave the “Submit One” option a default value of nothing. You can take … Read more
If you need the labels to the left of the fields like that, just go ahead and use a table. Not only do tables degrade nicely on older browsers, but they auto-size the column of labels to the text in them (assuming you use white-space: no-wrap on the cells containing the labels, and/or — and this … Read more
document.activeElement, it’s been supported in IE for a long time and the latest versions of FF and chrome support it also. If nothing has focus, it returns the document.body object.
The hidden html attribute also works to hide an element. <p hidden>This paragraph should be hidden.</p> To bind to Model: <p hidden=”@HideLabel”>I am Hidden When HideLabel == true</p> <p hidden=”@(!HideLabel)”>I am Hidden when Hidelabel == false</p> <button @onclick=”@Toggle”>Show/Hide</button> @code { private bool HideLabel { get; set; } = false; private void Toggle() { HideLabel = … Read more
Alasdair’s approach is nice but outdated. Radev’s approach looks quite nice and as mentioned in the comment, it strikes me that there is nothing about this in the documentation. Apart from those, since Django 1.7 there is a function get_changeform_initial_data in ModelAdmin that sets initial form values: def get_changeform_initial_data(self, request): return {‘name’: ‘custom_initial_value’}
You should post it with ajax, this will stop it from changing the page, and you will still get the information back. $(function() { $(‘form’).submit(function() { $.ajax({ type: ‘POST’, url: ‘submit.php’, data: { username: $(this).name.value, password: $(this).password.value } }); return false; }); }) See Post documentation for JQuery