form_for not rendering :html => {}

已查看 37 次
跳至第一个未读帖子

Mendel

未读,
2016年1月27日 16:01:512016/1/27
收件人 Ruby on Rails: Talk
Hi I am trying to disable chrome's html5 validations. I have added 
:html => {:novalidate => 'novalidate'}
to the form tag but when I check the form in the browser it is not there and the validations keep me from submitting the form.

Here is all the relevant (I think) code.

Enter code here...form_for(:customer, url: {:action => 'update', :id => @customer.id, :account_settings => true},:html => {:novalidate => 'novalidate'}) do |f|
          = render(:partial => 'form', :locals => {:f => f})

And this is what the form shows in HTML
<input class="form-control" id="customer_contact_email" name="customer[contact_email]" pattern="false" type="email">

Thank you.

Colin Law

未读,
2016年1月28日 04:53:392016/1/28
收件人 Ruby on Rails: Talk
Are you saying the form tag does not show at all?
Is it ok in a different browser?
Have you got the = sign?
<%= form_for...

Colin

Mendel Schneerson

未读,
2016年1月28日 09:53:332016/1/28
收件人 rubyonra...@googlegroups.com
Sorry I put the wrong line of HTML, the form works:

Here it is in Chrome

<form accept-charset="UTF-8" action="/customer/5" method="post">


What is interesting is that in Firefox the tag shows up and works fine:

<form accept-charset="UTF-8" action="/customer/5?account_settings=true"
method="post" novalidate="novalidate">

--
Posted via http://www.ruby-forum.com/.

Walter Lee Davis

未读,
2016年1月29日 12:43:042016/1/29
收件人 rubyonra...@googlegroups.com

> On Jan 28, 2016, at 9:52 AM, Mendel Schneerson <li...@ruby-forum.com> wrote:
>
> Sorry I put the wrong line of HTML, the form works:
>
> Here it is in Chrome
>
> <form accept-charset="UTF-8" action="/customer/5" method="post">

Is this looking at the raw HTML, or the rendered DOM? Chrome *might* be being pedantic here, and refusing to show GET attributes in a POST form. I recall somewhere in the mists of time that while that may work, it may also not be *standard* and thus a conforming UA would be within its rights to drop it, since POST trumps GET in all cases. See if the form works uniformly when you add a hidden field to it with :account_settings as the name, and remove the querystring from the form action. If you add that with a f.hidden_field helper, then you will need to change your controller to access the attribute from within the parent object's params hash, i.e.: params[:customer][:account_settings] rather than params[:account_settings].

Walter

>
>
> What is interesting is that in Firefox the tag shows up and works fine:
>
> <form accept-charset="UTF-8" action="/customer/5?account_settings=true"
> method="post" novalidate="novalidate">
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bbecfb64afafc7414dbd6a51584ef941%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Colin Law

未读,
2016年1月29日 13:28:042016/1/29
收件人 Ruby on Rails: Talk
On 29 January 2016 at 17:42, Walter Lee Davis <wa...@wdstudio.com> wrote:
>
>> On Jan 28, 2016, at 9:52 AM, Mendel Schneerson <li...@ruby-forum.com> wrote:
>>
>> Sorry I put the wrong line of HTML, the form works:
>>
>> Here it is in Chrome
>>
>> <form accept-charset="UTF-8" action="/customer/5" method="post">
>
> Is this looking at the raw HTML, or the rendered DOM? Chrome *might* be being pedantic here, and refusing to show GET attributes in a POST form. I recall somewhere in the mists of time that while that may work, it may also not be *standard* and thus a conforming UA would be within its rights to drop it, since POST trumps GET in all cases. See if the form works uniformly when you add a hidden field to it with :account_settings as the name, and remove the querystring from the form action. If you add that with a f.hidden_field helper, then you will need to change your controller to access the attribute from within the parent object's params hash, i.e.: params[:customer][:account_settings] rather than params[:account_settings].

Further to this a good plan is to copy/paste the complete generated
html into the html validator
https://validator.w3.org/#validate_by_input

Often when different browsers behave differently for the a site is it
down to invalid html, which the two browsers are interpreting
differently.

Colin
回复全部
回复作者
转发
0 个新帖子