-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling forms within live. #6
base: main
Are you sure you want to change the base?
Conversation
lib/live/form.rb
Outdated
class Form < Live::View | ||
|
||
#returns [String] javascript code to execute when the form is submitted. | ||
def handleForm(details=false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably call this forward_submit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/live/form.rb
Outdated
end | ||
end | ||
|
||
#Render the element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a space between #
and the comment, e.g.
# Render the form element.
The returns
line is probably not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/live/form.rb
Outdated
#Handles an incoming event. | ||
# @parameter load [String] the parsed message from the view layer, | ||
# which includes the details and the serialized form data. | ||
def handle(event, message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you should introduce a new method above called def submit(form_data)
This method should then invoke that with the argument rather than setting an instance variable.
The sub-class can be responsible for updating data and/or form data. Maybe we should repurpose @data
- i.e. fields that are stored in the form are serialized as part of the form itself anyway, so it doesn't need to be part of the data-
attributes. Not sure best way.
lib/live/page.rb
Outdated
@@ -99,7 +99,7 @@ def run(connection) | |||
Console.logger.warn(self, "Could not resolve element:", message) | |||
end | |||
elsif id = message[:id] | |||
self.handle(id, message[:event]) | |||
self.handle(id, message[:event], message[:event][:details]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? I believe the message[:event]
can be decoded by the handle
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me so far, I've given you some feedback. |
now disregarding `details`
@pharmac1st do you want to try reworking this PR on the latest version of |
Description
As required by the issue, a new class
Live::Form
has been created for the server side handling of forms, it is a child function ofLive::View.
Live::Form
provides a new class variable@recieved_form
which is a serialized hash version of the form data. This PR also comes with a fix for thedetails
argument not being passed properly. Two new javascript Live class functions are added for clientside handling of forms, see the live-js PR.Types of Changes
Testing
I tested my changes locally.