Skip to content

Commit 66fa334

Browse files
committed
Create form test
1 parent 63e23d5 commit 66fa334

File tree

8 files changed

+51
-9
lines changed

8 files changed

+51
-9
lines changed

tests/test_app/components.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from reactpy import component, hooks, html, web
1010

1111
import reactpy_django
12-
from reactpy_django.components import django_form, view_to_component, view_to_iframe
12+
from reactpy_django.components import view_to_component, view_to_iframe
1313
from test_app.models import (
1414
AsyncForiegnChild,
1515
AsyncRelationalChild,
@@ -22,7 +22,6 @@
2222
)
2323

2424
from . import views
25-
from .forms import BasicForm
2625
from .types import TestObject
2726

2827

@@ -693,10 +692,3 @@ async def on_submit(event):
693692
html.div(f"Mutation State: (loading={user_data_mutation.loading}, error={user_data_mutation.error})"),
694693
html.div(html.input({"on_key_press": on_submit, "placeholder": "Type here to add data"})),
695694
)
696-
697-
698-
@component
699-
def basic_form():
700-
return django_form(
701-
BasicForm, bottom_children=(html.input({"type": "submit"}),), auto_submit=True, auto_submit_wait=0
702-
)

tests/test_app/forms/__init__.py

Whitespace-only changes.

tests/test_app/forms/components.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from reactpy import component, html
2+
3+
from reactpy_django.components import django_form
4+
5+
from .forms import BasicForm
6+
7+
8+
@component
9+
def basic_form(form_template=None):
10+
return django_form(BasicForm, form_template=form_template, bottom_children=(html.input({"type": "submit"}),))

tests/test_app/forms.py renamed to tests/test_app/forms/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ class BasicForm(forms.Form):
3636
label="combo", fields=[forms.CharField(), forms.EmailField()], initial="example@gmail.com"
3737
)
3838
password_field = forms.CharField(label="password", widget=forms.PasswordInput)
39+

tests/test_app/forms/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.urls import path
2+
3+
from .views import form
4+
5+
urlpatterns = [
6+
path("form/", form),
7+
]

tests/test_app/forms/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.shortcuts import render
2+
3+
4+
def form(request):
5+
return render(request, "form.html", {})

tests/test_app/templates/form.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{% load static %} {% load reactpy %}
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
5+
<head>
6+
<meta charset="UTF-8" />
7+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9+
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}" />
10+
<title>ReactPy</title>
11+
<style>
12+
iframe {
13+
width: 100%;
14+
height: 45px;
15+
}
16+
</style>
17+
</head>
18+
19+
<body>
20+
<h1>ReactPy Forms Test Page</h1>
21+
<hr>
22+
{% component "test_app.forms.components.basic_form" %}
23+
<hr>
24+
</body>
25+
26+
</html>

tests/test_app/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
path("", include("test_app.pyscript.urls")),
3535
path("", include("test_app.offline.urls")),
3636
path("", include("test_app.channel_layers.urls")),
37+
path("", include("test_app.forms.urls")),
3738
path("reactpy/", include("reactpy_django.http.urls")),
3839
path("admin/", admin.site.urls),
3940
]

0 commit comments

Comments
 (0)