It's possible to dismiss a Modal View only with a Button? I don't want that the user can swipe down to dismiss the Modal.
Related
In django admin, when there is a ForeignKey or ManyToManyField, there is [+] button to add it like this :
How can I make that [+] button with popup window using forms in templates ?
UPDATE 01:
I WANT TO CREATE POPUP WINDOW LIKE THIS IN MY TEMPLATE, NOT IN MY ADMIN PANEL.
You can use the admin reverse urls.
So in code:
<button class="button" onClick="window.open('{% url 'admin:model_add' %}');">
<span class="icon-plus">+</span>
</button>
This is not tested! It's just a quick try out of my brain.
I have two Forms called Form1 and Form2. In Form1 I have two buttons and one Label. One Button to open Form2 by calling Form2->Show().
The second Button sets the Caption of Label1 in Form1 to e.g. "Hello world".
In Form2 I have another button and Label. The button in Form2 sets the Label in Form2 to "Hello universe".
I like to pass the OnClick-Event of the Button in Form1 to the OnClick-Event of the Button in Form2.
That means, when I click on the Button in Form1, the Label in Form1 should be set to "Hello world" and immediately fires the OnClick-event in Form2 to set its Label to "Hello universe".
That should be done not by calling the OnClick-Event of Form2 in the OnClick-event in Form1. That would be too easy. Instead I like to assign it from Form2. Something like Button1->OnClick = Form1->Button1->OnClick
Is there any way to realize it?
Thanks
Christian
I have a form that subclasses PhoneNumberForm from the django-two-factor-auth-library. It renders a text box in which to enter phone number, and a Back button and Next button beneath it. The issue is that when the form is filled out and the user hits the 'Enter' key on their keyboard, the Back button is triggered.
I have tried swapping the two buttons, which gives me the behavior I want, but not the correct layout. But I do see that whichever button is defined first in FormActions gets selected on hitting Enter.
I have also tried adding an 'autofocus' field to my Next button, but that only focuses on the button when the page loads, not after I've switched focus to the text box and typed in a number.
I would like to maintain the order I currently have (Back button on the left, Next on the right), but have the Enter key trigger the Next button. How do I do this?
from crispy_forms.helper import FormHelper
from crispy_forms import layout as crispy
from crispy_forms import bootstrap as twbscrispy
def __init__(self, **kwargs):
super(PhoneNumberForm, self).__init__(**kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form form-horizontal'
self.helper.label_class = 'col-sm-3 col-md-4 col-lg-2'
self.helper.field_class = 'col-sm-9 col-md-8 col-lg-6'
self.helper.layout = crispy.Layout(
crispy.Fieldset(
'',
'number'
),
twbscrispy.FormActions(
twbscrispy.StrictButton(
_('Back'),
css_class='btn-default',
type='submit',
value='method',
name='wizard_goto_step',
),
twbscrispy.StrictButton(
_('Next'),
css_class='btn-primary',
type='submit',
)
)
)
You browser is using <Enter> for the first button where type = "submit" in the form.
If you change your "Back" button type to "button", then your "Next" button will be the first submit button in your form, and <Enter> will activate it.
You can still get your "Back" button to submit your form, if you use an "onclick" attribute, and give your form an "id" attribute.
e.g.
# ...
self.helper = FormHelper()
self.helper.form_id = 'wizard_form_id'
# ...
twbscrispy.StrictButton(
_('Back'),
css_class='btn-default',
type='button',
value='method',
name='wizard_goto_step',
onclick="document.getElementById('wizard_form_id').submit();",
),
twbscrispy.StrictButton(
_('Next'),
css_class='btn-primary',
type='submit',
)
I am extending the Django admin. I have a click button on the change_form that takes me to another customized page. I want to add a button on the customized page to take me back to the change_form (keeping track of the instance I am working on by the object_id). What do I put in the href of the click button to go back to the change form? My guess was this:
<a class="changeform" href="{% url 'admin:change_form' object_id %}">{% trans "Click HERE to return." %}</a>
but that does not work. Thanks in advance for any advice.
Your view name (instead of admin:change_form) should be along the lines of admin:myapp_mymodel_change
As an example we have a log in view with 'username', 'password' and 'country' fields and a 'login'.
How can one invoke the action related to the 'login' button when pressing enter on any of the inputs in a group.? For instance, all inputs within a container of some sort (div, form, fieldset, etc).
To get your form controls trigger the sumbit action you could define your controls of type submit.
...
{{input type="submit" ...}}
...
<button type="submit">...</button>
...
or the more elegant way is to having your parent view catch all the events and trigger the submit once, but this depends how nested your view is.
Hope it helps
Put your action on your form tag, like so:
<form {{action yourAction on="submit"}}>
{{input text}}
{{input text}}
<button type="submit"></button>
</form>
This will cause your event to fire whenever the form is submit (by clicking the button, by hitting enter in a field, etc.