React hook form | Browsers auto fill. How to make so that input knows about the data from auto fill - react-hook-form

How to make so that input knows about the data from auto fill? You can go to codesandbox, add some auto-fill data, refresh a page and see this problem. Is there any idea how to fight it?
It doesn't work:
autoComplete="off"
autoComplete="new-password"
autoComplete="new-password"
There is a code:
https://codesandbox.io/s/react-hook-form-mantine-npvcof?file=/src/App.js
This thing we get at first:

Considering that I use the mantine lib this way helped me
https://ui.mantine.dev/component/floating-label-input
Anyway, I think it can help to come up with an option how to work it out

Related

Conditional Validation ie. Requiring a field only if a certain radio button is checked?

This is more of a pointing in the right direction sort of thing. I'm currently working on a project where a handful of fields will be hidden until a radio button is checked, therefore also not required until then. So tick the specific radio button, fields show up and they are now required on submit with the [Required] DataAnnotations attribute in the model.
I went down the path of trying to use MVC Foolproof and [RequiredIf], but didn't have much luck considering the outdated js files necessary and was wondering if someone else had a simpler solution.
I appreciate any input. I feel like this isn't too uncommon of a task but had a lot of difficulty finding a solution via Google.
I am sure you can accomplish this with using Javascript/Jquery.
Like so:
if($('#idNameOfRadioBtn').is(':checked')){
$('#idOfFieldNameThatIsNowRequired').attr('required');
}
else{
$('#idOfFieldNameThatIsNowRequired').removeAttr('required');
}
Let me know if this helps!
I suggest that you use angularjs for this as it is built for it. If you are not familiar with angular validation, here is a great article in scotch where it gives a really good demonstration. Good luck!
Hide and show fields based on ng-if directive and make field required using the required attribute. That's it!
<input type="text"
name="name"
class="form-control"
ng-model="user.name"
ng-if="user.required"
required>
Angular Validation

Editable select/combobox

is there any way (or plugin) to display editable combobox? I have a set of options, but I would like to give possibility to enter custom value.
I've searched the documentation, and I can't find way to do this. I made workaround with javascript, but I'm looking for more elegant solution.
I'm pretty sure that there simply is no HTML form element that does this, and so Rails can't provide you with a helper. As you said, you can work with JS to create something similar (and there should be JS libraries/plugins already out there), or you could just use a select element and add a text field next to it for new values.
HTML5 specification doesn't define such an element. So you may either continue using JS, either try to use autocomplete feature of an input element (although it is not exactly what you want and doesn't compatible with old browsers).

Adding * to required form labels

Does anybody have a nice way of adding * to required form labels, without having to turn to tools like SimpleForm?
I did not like the way SimpleForm added all these weird wrappers and classes to my stuff. I thought the point of SimpleForm was to allow you to write simple, semantic form ERB (which it most certainly does) - but not at the same time mess up your existing layout by adding wrappers and classes at random. I always style my forms before I bring them to Rails, so I like to tell it what classes to use, not the other way around.
Can't you just simply style your labels?
Your label:
<label class="required">MyRequiredField</label>
Your css.
label.required:after{content:"*"}
Or am I missing what you're trying to accomplish?
If you don't like their solution you can see how they implemented and roll your own:
https://github.com/plataformatec/simple_form/blob/master/lib/simple_form/helpers/required.rb

How do I remove HTML tags from within a text area using MVC 3?

I have difficulty getting a value from a text area of the CKEditor
when I save something that has nothing inside the textarea HTML tag. In this case, it puts this text inside:
<html>\r\n\t<head>\r\n\t\t<title></title>\r\n\t</head>\r\n\t<body>\r\n\t</body>\r\n</html>\r\n"
Is there some way to strip off all these html tags?
I'm using MVC 3, and I've researched something about: Content(Server.HtmlEncode),
but I'm still not 100% if this is the best way to do this kind of treatment.
I found a class listed below that looks like it should solve your problem. Just add it to your solution and you can then call it statically and strip the html.
This kind of assumes that you are wanting to do the stripping of html on the server side.
On a side note not accepting answers like you are doing is hazardous to people willingness to help...I'd recommend that you reward the people that are helping you if you'd like to continue getting help!
Link to Solution
#Html.DisplayTextFor(modelItem => item.content)

Rails + Ajax - update view based on combo-box choice?

Just a heads-up, I'm a total beginner as far as ajax is concerned and am just trying to find my way around it, so please bear with me :)
I have a View with a combo box in it (generated through a collection_select) and I display some data on the side of that form that essentially gives more details about the user's choice.
What I'd like to achieve is to be able to change that description on the side as soon as the customer makes a different selection in the combo. Basically, figure out what the current choice is, request data from the model, display returned data on the screen.
What's the simplest / most elegant way of achieving that? I think understanding the process would be a good launching ramp into the rest of the async View world for me.
Thanks!
I don't think ajax is necessary in this situation. Simply preload all the description values and store them in hidden divs:
<div class="description" id="choice1">
description for choice1 ...
</div>
...
Then hide them all:
// somewhere in your stylesheet
div.description {
display: none;
}
And finally on client side, bind to wanted events of the combo box:
// checkout documentation for other events, like select
$('some_id').change(function(data){
$('div.description').css('display', 'none');
var id = // get information about selected choice and figure out the id of description
$('div.description#' + id).css('display', 'block');
});
Chekout documentation for exact details but the main idea should be clear. In this way, you'll save yourself some unnecessary requests to your server.

Resources