select2 required and default notification - jquery-select2

I;m using select2 with a required field. When the field is not filled out, in Chrome the notification that it's a required field is out of place. In FF, I can't even see the notification, so it just prevents the form from being submitted.
any ideas how to resolve this?

Related

updating/dismissing message after dialog submitted

Is there a way to do any of the following:
a. Update a chat message that initiated a dialog.
b. Store "hidden" fields in a dialog.
Basically, I have a bot message that opens from a button on a message attachment. I know when the user clicks the button, I get the ts of the message and at that time I could alter it. However, the workflow is not complete until the user has submitted the dialog, but the submit on the dialog loses all the original_message stuff and the ts of the dialog being submitted no longer corresponds with the original, calling message.
If there was a mechanism to store hiddens, I could stash the original ts or the response url on the form itself.
Thanks! This is my first slack workflow, so any advise is appreciated as usual!
.....
The suggested duplicate answer refers to an interactive message, which I'm using to call the dialog already.
However, that isn't where my problem is, it is the dialog submission.
You don't have any access to the button elements on a dialog and the dialog element can only have 5 elements of type: text, select, text area. Plus it's a bit overkill considering that a action invocation from an interactive message actually includes the original message in the post back to your server.
So slack dev support got back to me:
Thanks for writing in, this is a great question!
You can use the callback_id parameter when calling dialog.open to store a string that will help your app locate the message. This callback_id will be returned to you in the dialog submission.
In your case, you could store the original message's ts and channel_id so that > you can locate the message to update.
I hope this helps! Let me know if you have any further questions!
So, it's a bit hacky (imo), but i did get it to work so I thought I'd close this question in case anyone else ran into this.
I'm just parsing the original ts value inside the callback w/ some other data i can use when the form submits. The only limitation to this is that it only stores 200 characters but that should be sufficient considering that is in addition to the 5 fields you have on the dialog and the other stuff slack gives you in the post (user, channel, etc).

removing saved password from textboxes for forms inside the application

I have an application, where a normal login is present. Once login, user can create other users and we have forms with username and password fields present in those forms.
Now my problem is, when login in the application and browser asks for remember password. If I say Yes and then I go to create other users then the forms show with the username password already filled that I used for login.
I want to remember password for the main login form but don't want those to display when I am creating other users. This is mainly coming in chrome. Might come in other browsers on in mobile browser as well.
I tried clearing the text box on document ready and setting autocomplete to off for the form. but didn't work out. If I remove the type="password" attribute from the password textbox, then the browser doesn't auto fill the username/password textbox but that causes the password to display.
Any suggestion to overcome this issue are welcome.
use AutoComplete=off
The autocomplete attribute specifies whether or not an input field should have autocomplete enabled.
<input type="email" name="email" autocomplete="off">
Autocomplete allows the browser to predict the value. When a user starts to type in a field, the browser should display options to fill in the field, based on earlier typed values.
Note: The autocomplete attribute works with the following types: text, search, url, tel, email, password, datepickers, range, and color.
Update
apparently chrome ignores autocomplete="off"
This question will help you with that
Chrome Browser Ignoring AutoComplete=Off
Update 3
There is also another solution that works for people to and that is use autocomplete="false"
ref w3school
You can't tell the browser to only auto fill one set of usernames and passwords! Any sort of instructions to the browser regarding user names and passwords would be a security risk.
Your best bet would be to have the input controls have different ids and names so that the browser does not think this is the same form that it has saved information for.

How does Rails persist text in input field?

I have a regular text input field, whose value is submitted via AJAX. After I migrate away from this page, and hit Back button, I can still see the value of the field there.
My questions are:
Does most of modern browsers support this user-entered values?
How can I remove the persisted value using Rails?
Thank you.
Your browser is remembering the form input values and displaying them when you go back. This likely doesn't have anything to do with Rails*.
You can't really do anything via Ruby/Rails code to change this behavior, but you can do it with JavaScript. Here's a random SO question that covers it: Reset form on Back button.
I'm not sure if there's a perfect way to handle this in every browser. Also note that many users would prefer that the browser keep the form values they've entered.
Note: I only qualify with "likely" because it is possible to write an app that explicitly remembers form values and restores them when the page is visited again, but by default, Rails isn't going to do that. It'd involve a fair bit of Rails and JavaScript code.
Does most of modern browsers support this user-entered values?
Yes, I believe they all support it to various degrees
How can I remove the persisted value using Rails?
This is a client side issue, not a Rails issue. You could use javascript to clear the input fields
A similar question and answer: Clear all fields in a form upon going back with browser back button
BFCache? https://developer.mozilla.org/en-US/docs/Working_with_BFCache

ASP.NET MVC 3 - Remote attribute onsubmit?

I've discovered that the Remote attribute wont fire if you navigate with your keyboard to the submit button, hence the onchange event for the remote attribute wont fire (at least not always) - Is there a workaround for that?
Thanks in advance.
It doesn't matter which rule you have use. The behavior would be the same.
If it doesn't validate, you probably have two issue to concern about:
1. the method onkeyup will fire only if you have submitted the form at least once.
2. maybe you have some JavaScript error somewhere while it try to run it (check if it has run with no error).
remote rule just like other rules, will fire 'onfocusout' and 'onkeyup' and 'onclick'. The latter will fired for checkbox and radio buttons.
onkeyup event will fired(on your key up) if you have submitted your form for once.
onfocuseout event will fired if you leave your input with your mouse or keyboard(with tap key).
And one last thing. all rules will be checked before you submit your form, even with $(Form).submit()

Form retaining values after refresh

So I've inherited this legacy rails codebase and there's a bug i need to fix where a given form is retaining values (that have not yet been saved to the DB) even after Page Refresh.
Use Case:
User fills data in form but does not press submit.
User Clicks refresh button on browser.
The Values in the form are retained instead of refreshing the whole page.
Any ideas where I can start looking? In my brief, limited Rails experience, this is not the sort of thing that happens by default, so it must be coded somewhere?
Sometimes browsers will do this. (I'm not talking about auto-fill drop-downs, which browsers also do... just talking about forms that are partially filled out, never submitted, and are then refreshed).
Make sure the values in the fields are actually coming from your Rails app by checking the HTML source window.
Values provided by the browser due to previous entry won't be in the VALUE attribute, but server-provided ones will be.
Some options for avoiding this might be:
Send the user to the form using a POST. Thus, any refresh results in a "do you want to resubmit" etc. I don't think the browser will pre-fill any fields in this situation (same as when a user posts and then hits the back button).
Use the onload() event to wipe out the form field values.
There's probably a simpler solution... Ctrl-F5 sometimes does the trick, but I think I've seen even that not work before.
Tell user to press CTRL+F5
--
edit
if you can't tell the user to press CTRL+F5 (which always in my experience works unless the browser is buggy, or unless something else is going wrong), just trip form.reset() in the onload event. This will clear the fields in the form to the default values. If you have default values in the fields though, (like <input type="text" value="enter name here" />) then when you trip .reset(), it will reset to the default value.
I just ran into this problem as well, and even <body onload="myform.reset()"> didn't work. This was particularly a problem because, for better or for worse, I'm using hidden inputs as counters (to keep track of a dynamic number of file upload fields, for example). These obviously need to be reset on reload to keep non-applicable warning messages from appearing. I "fixed" it for my in-house purposes by abandoning the reset button in favor of a link. Instead of <input type="reset"/> I'm using Reset (the filename is index.php). Far from elegant, but it works for my purposes.
I ran into this issue with a Rails 7 app. When navigating to a view with a form everything is blank, when I hit refresh all the inputs get filled by the browser (not by Rails). To keep the inputs blank I used the autocomplete attribute, which is supported by all modern browsers:
<!-- for the whole form -->
<form method="post" action="/form" autocomplete="off">
<!-- for a specific input element -->
<input type="text" id="foo" name="foo" autocomplete="off">

Resources