why cant I submit a customized form with this button

42 views
Skip to first unread message

Maurice Waka

unread,
May 5, 2017, 1:45:14 AM5/5/17
to web2py-users

I have a web2py app, with two problems:

1. I can submit the customized form with pressing 'Enter' but when clicking the button, I get an error.

2. when pressing 'Enter', the form is submitted but the page is refreshed immediately. How can i stop that?

Here is the code; This does not work

<div class="message_input_wrapper">
    {{=form.custom.begin}}
    <input name="body" class="message_input" placeholder="Type your message here..."/>                
    {{=form.custom.end}}                
</div>
<button type="submit" class="send_message">Send</button>

This does not work either:

<div class="message_input_wrapper">
    {{=form.custom.begin}}
    <input name="body" class="message_input" placeholder="Type your message here..."/>                
    {{=form.custom.end}}   
    <button type="submit" class="send_message">Send</button>             
</div>

This is the js code:

(function () {
var Message;
Message = function (arg) {
    this.text = arg.text, this.message_side = arg.message_side;
    this.draw = function (_this) {
        return function () {
            var $message;
            $message = $($('.message_template').clone().html());
            $message.addClass(_this.message_side).find('.text').html(_this.text);
            $('.messages').append($message);
            return setTimeout(function () {
                return $message.addClass('appeared');
            }, 0);
        };
    }(this);
    return this;
};
$(function () {
    var getMessageText, message_side, sendMessage;
    message_side = 'right';
    getMessageText = function () {
        var $message_input;
        $message_input = $('.message_input');
        return $message_input.val();
    };
    sendMessage = function (text) {
        var $messages, message;
        if (text.trim() === '') {
            return;
        }
        $('.message_input').val('');
        $messages = $('.messages');
        message_side = message_side === 'left' ? 'right' : 'left';
        message = new Message({
            text: text,
            message_side: message_side
        });
        message.draw();
        return $messages.animate({ scrollTop: $messages.prop('scrollHeight') }, 300);
    };
    $('.send_message').click(function (e) {
        return sendMessage(getMessageText());
    });
    $('.message_input').keyup(function (e) {
        if (e.which === 13) {
            return sendMessage(getMessageText());
        }
    });


Kiran Subbaraman

unread,
May 5, 2017, 3:06:05 AM5/5/17
to web...@googlegroups.com
The `{{=form.custom.end}}` has to be after the submit button. http://web2py.com/books/default/chapter/29/07/forms-and-validators#Custom-forms
________________________________________
Kiran Subbaraman
http://subbaraman.wordpress.com/about/
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maurice Waka

unread,
May 5, 2017, 10:56:28 AM5/5/17
to web...@googlegroups.com
Still no change. How about the preventing page refreshing 

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/oEjq7ACIqwI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

Jim S

unread,
May 5, 2017, 11:06:56 AM5/5/17
to web2py-users
Can you strip out all of your javascript and confirm that the standard form submission is working with Kiran's solution?

Then, put your javascript back in and watch the javascript console during execution to see where you're getting hung up?

Then for your second issue, have you looked at javascript/jquery solutions?  Such as http://stackoverflow.com/questions/895171/prevent-users-from-submitting-a-form-by-hitting-enter

-Jim
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/oEjq7ACIqwI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Maurice Waka

unread,
May 5, 2017, 11:17:06 AM5/5/17
to web...@googlegroups.com
Without js, form still only submitted by hitting enter. I'll check this other link. Regards 

To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

Jim S

unread,
May 5, 2017, 11:25:40 AM5/5/17
to web2py-users
Can you try the following:

1.  <input type="submit" value"Send" />

or

2.  {{=form.custom.submit}}     and then control your text and classes through your controller.

-Jim


To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Maurice Waka

unread,
May 6, 2017, 7:12:18 AM5/6/17
to web...@googlegroups.com
Second option is perfect. Thanks for the information. 

To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages