Home > database >  Show An Alert message Before Submitting the Page Django
Show An Alert message Before Submitting the Page Django

Time:07-20

I want to create a alert message before submitting the page , my

form.py

class NameForm(forms.ModelForm):
   translated_names = TranslationField()

class Meta:
    fields = "__all__"
    model = models.Name

admin py

class NameAdmin(MasterDataBaseAdmin):
   form = forms.NameForm
   inlines = [AddressInline, RegistrationTypeInline]
   queryset = models.Name.objects.prefetch_related(
    "names", "name__id", "registrationstype"
)

views.py

class NameViewSet(viewsets.ReadOnlyModelViewSet):
     queryset = models.Country.objects.supported().prefetch_related("names", 
      "registrationstype")
      serializer_class = serializers.NameSerializer

I want to just add this meesage in the Message Box

"Are You Sure You Want To Save The Page!"

CodePudding user response:

Try this in your HTML

<input type="submit" onclick="return confirm('Are you sure?')" />

In your html you probably have something like that

<form action="/your-name/" method="post">
<label for="your_name">Your name: </label>
<input id="your_name" type="text" name="your_name" value="{{ current_name }}">
<input type="submit" onclick="return confirm('Are you sure?')" />
</form>

onclick="return confirm('Are you sure?')" here is your massage box

  • Related