I research about validate form.
I understand Ember does not know how to work with attributes validation HTML5(required, pattern ). For this need created functions with algorithm validation in model for each form. And run that function when click submit button
I have a question: I have possibility show standard HTML5 error message for not valid input?
For example: I check all fields(in Ember model) and one field not valid. We need for this field show notice that field is not valid at help HTML5(maybe run for this element valid() function) How do that?
Have a look at this project ember-easyForm and this introductory blog post.
It makes creating forms in ember a lot easier, and it also includes validation.
Hope it helps.
Related
I could use some help to understand the fundamentals between Blade views and the use of Vue.JS in combination.
I have a form which is created by a Blade Template.
I now want to help the user filling out the form by pre-filling the "End-Date" depending on which duration he chooses in the dropdown.
Also, if he chooses "no duration", the End-Date should be hidden and so on.
Now i don't have experience with JavaScript. It should be possible to do things like this with JQuery but as far as i understand, Laravel and Vue.JS seem to be a good combination. So i wanted to go with it.
I don't understand how to combine Blade with Vue.
Can i just add things like <p>#{{ message }}</p> into the template? I tried this, but where has the JavasScript-Code to go? Putting it in the app.js gives me a warning:
[Vue warn]: Property or method "message" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
I've been reading of Vue-Components, but putting the whole form or parts of it into a component would Blade prevent to render the form, correct?
Maybe you could help me into the right direction. Thanks alot.
First Of all you need to know the basics of JavaScript. Although you had jumped to js framework that will not help you. Learn js first.
If you only want to maintain the End-date by the duration , it can be done by basic js or jquery. You don't need to adjust vuejs.
Rather if you being compelled to vuejs , it can be done on a component and can be rendered by catching an id of any div tag ...
I have written python code that analyses two text sources and compares them.
I'd like to implement this dynamically via two text boxes that a user could either type into or manually upload. I have already begun coding this using HTML. Would it be better to implement a widget or the models instead to make the text area boxes?
Edit:
I wrote this question when I was just figuring Django out, so forgive me if it sounds confusing. But everyone starts somewhere. I'm unable to delete the question as contributions have been made already. YouTube courses proved helpful in learning the basics, if any beginners stumble upon this.
You use a form object. Django has form objects (https://docs.djangoproject.com/en/2.0/topics/forms) that take a model and translate it into html elements. So I guess in a way, you implement the model but I want to stress that that's not actually what's happening from a technical standpoint. A better way to say it is that you're implementing forms. The reason I stress this so much is so that you understand what's really going on so that you don't have misunderstandings that end up costing you in code clarity and readability.
So to answer your question, you can implement django forms to do this very easily. The way you implement it depends on your models and how they are designed since the forms use the models to create the right html form elements. If you're dealing with one model that will be instantiated by the form input, create a model form. This will take the input from the form and create your model instance. If you're dealing with one form that uses multiple models, then use a generic form. In this case, you will have to write your own save method that does the actual logic of the form.
One other thing to add... No matter what, your end result will always be a widget on the HTML in the end. Django forms translate a model class into a form element with input elements. If you didn't use Django forms, you would still do the translating, but you would have to do it from scratch.
I hope this helps and that I correctly understood your question.
In PHPfox, i want to call "Pages" name in drop-down in Signup form. Reason for calling "Pages", Actually i have created many pages for college name & that are saved in database. So if someone comes for signup, i want to show them college name in drop-down (which are basically "Pages").
Please help me.
Thanks in advance.
You will need 2 plugins, one to show the HTML and one to process what to do with the user input:
1) Make a plugin that fetches the pages, maybe the hook user.component_controller_register_1 or another in that controller would do but otherwise you can always use a low level hook like run_start and check if its the section where you want it.
To show the HTML you have 2 options: include a JS file to populate the sign up form with anything that you want, or if you have a custom template you can just assign the array to the template variable and look through it in your template.
2) Once the html part is showing and working make a plugin for the sign up routine, I think the hook user.service_process_add_1 should be enough given its location.
Dont forget that the input name for the signup is an array, so your drop down needs to look somewhat like this:
<select name="val[my_dropdown]">
I'm evaluating AngularJS and so far I'm very enthusiastic about it. But there's something missing on the validation front: the available options, such as the built-in mechanisms and the AngularUI initiative, implement validators through directives and, as such, every validation should be declared in the view:
<form ng-controller="SomeController">
<!-- Notice the 'required' attribute directive below: -->
<input type="text" ng-model="user.name" name="uName" required />
</form>
In this example, the view is defining that user.name is required. It's like saying the view defines the proper shape of the model. Isn't it a little backwards? Shouldn't the view reflect the states, including error states when it's the case?
Am I mistaken? I'm wondering if it's possible to apply any validators in the controller, signaling the model's data as valid/invalid, and updating the view accordingly (painting form controls with red, showing error messages, clearing previous errors and so on). I'm assuming AngularJS is powerful enough for this, but in the docs and samples so far I just haven't seen anything like I've described above. Thanks!
I guess its all about perspective. The way I see it is, you are defining a view which contains a form and that form contains an input of type text. It is this text input that you are marking as required. If you note, angular does not care if the text is user.name or user.age or whatever else. Its just associating that text input with required. So its just validating that text input and the model associated with that model is the final result ( the place where the value goes in if the validation passes! ).
Have a look at
http://docs.angularjs.org/guide/forms
for custom form validations, if you want to to be doing validations that are not the default ones.
Since you already know the view that is getting produced in advance ( lets call it at compile time! ) , you can associate all validators in the view and hence wouldnt have to do it in the controller (which perhaps is for run-time validation! ).
the problem I have is that I have two sets of values in a drop down list. If type 'A' is selected I want a text box to be populated with a value from the database and be read only. If Type 'B' is selected the box is to be empty and editable.
My original code is written in jsp/struts and I have sort of achieved this by using
onchange="javascript:submit()" to reload the page, but this has the obvious drawback of saving any changes you have made which means you can't really cancel.
I also have other problems with the serverside validation due to this method.
Is there a way of making a jsp page reload on change, that way I could write javascript to change the way the page looks according to the values held in the session. That way the save/submit function will only be called when the page has properly been filled out and the server side validation will work as designed.
I know that this is something that AJAX is good at doing but I am trying to avoid it if possible.
AJAX is your only other option my friend, unless on the original page load you load all the other possible values of the Text Box so you don't need to go back to the database. Well, you could try putting the text box in an IFRAME, but you will probably run into more problems with that approach than just going with AJAX.
Without AJAX what you are asking is going to be difficult. Another option (which is ugly) is to write out all possible values for the second list box into a data structure like an array or dictionary.
Then write some javascript to get the values from the data structure when the user selects from the first list box. The amount of javascript you will have to write to get this done and to do it correctly in a cross browser way will be much more difficult than simply using AJAX.
Not sure why you'd try to avoid AJAX in today's world, the JS libraries out there today make it so simple it's crazy not to try it out.
I just had to replace a page that was written as Vincent pointed out. I assume at the time it made sense for the app, given the relative size of the data 4 years ago. Now that the app has scaled though, the page was taking upwards of 30 seconds to parse the data structures repeatedly (poorly written JS? maybe).
I replaced all the logic with a very simple AJAX call to a servlet that simply returns a JSON response of values for the 2nd drop down based on what was passed to it and the response is basically instant.
Good luck to ya.
One way is to change the form's action so that you submit the form to a different url than the "save" url. This lets you reload certain aspects of the form and return to the form itself, instead of committing the data.
<script>
function reload() {
document.forms[0].action="reloadFormData.jsp";
document.forms[0].submit();
}
</script>
<form action="saveData.jsp" method="post">
<select id="A" name="B" onchange="reload()"><!-- blah --></select>
<select id="B" name="B"><!-- blah B --></select>
<input type="submit">
</form>
If I understand you correctly, that you want either a dropdown (<select>) or a textfield (<input type="text">) depending on a choice (typically a checkbox or radiobuttons) somewhere above in a form?
I that case you may need to handle the two types of input differently on the server anyway, so why not have both the selectbox and textfield in the area of the form with different names and id and one of them hidden (display = none). Then toggle visibility when the choice changes. On the server you pick eiter the selectbox or textarea input (wich will both be present unless you disable (disabled="disabled") them too, wich I think is uneccesary) depending on the choice input.
Of course if you expect that the user usually just need the text-input, and a few times only, needing a massive list; it would be better to use ajax to retrieve the list. But if it's the other way around (you need the text-field only occationally), as I assumed above, it will be faster to have both present in the initial form.
If the drop down only contain easily generateable data, like years from now to houndreds of years back it could even be much faster (requiring less bandwidth on the server) to generate the data client side using a for loop in Javascript.
I know a taglib that can fit to your problem:
AjaxTags.
I use this taglib in my J2EE projects and it is very simple to integrate it into web applications.
This taglib give you several tags designed to execute AJAX request in your jsp files.
Here is the description of each tags: http://ajaxtags.sourceforge.net/usage.html
The tag which will help you is the ajax:select tag. It allows you to populate a select tag which depends on an other field without reloading the entire jsp page.
If you more informations about it, ask me and i'll try to answer quicky.
Along the lines of what Strindhaug said, but if you need dynamic data:
Could you have the backend write JS into the page, and then the JS would change the form as required? The backend could propagate some variables for descriptions and such, and then the JS could change/update the form accordingly. If you aren't familiar with this, libs like jQuery make things like this easier and more cross-browser than rolling-your-own (at least in my experience).
Aside:
If you're not using AJAX because it was hard to code (as I didn't for a while because my first experience was from scratch and wasn't pretty), as others have said, libs like MooTools and such make it really easy now. Also, there is not shame in using AJAX properly. It has a bad rap because people do stupid things with it, but if you can't simply write premade values into the form or you have to do live look ups, this is one of AJAX's proper uses.