HI I am new to cakephp so any help would be grateful.
I have created a form and with one of the fields when the user has filled in checks to see it it already exists and offers other suggestions. I have used the Ajax observerField method to do this. I want the user to be able to click on the suggested names(radioboxes) and then it update the field in the other form. What is the best way to achieve this in cakephp?
If it was me, I would create a form field
echo $form->input('otherfield');
Then use javascript to catch the click on the suggested radio, and copy the value into that field.
In jQuery,
$('#suggestions input[type=radio]').click(function(){
$('#otherfield').val() = $(this).val();
});
Then when the form is submitted you will have it in,
$this->data['Model']['otherfield']
Related
I am attempting to use $mdToast.updateTextContent() to update a toast and am unsuccessful. The docs don't go into detail on how to call it with a new message. My desire result would have the first toast display 'Adding account' then change to 'account successfully added'. Any help would be greatly appreciated.
I think the correct way to approach this using material design standards would be to only use the toast once the account has been added. The loading could be a spinner or maybe a loading bar (maybe like this http://materializecss.com/preloader.html)
Once the $mdToast is open, you're able to call updateTextContent (as you stated)
$scope.onAccountAdded = function() {
$mdToast.updateTextContent('Account successfully added')
};
We're watching the variable for changes and update the view automatically, once the value has changed.
https://github.com/angular/material/blob/master/src/components/toast/toast.js#L299
Here is a demo, which shows how it works.
http://codepen.io/DevVersion/pen/qNWewJ
I am using angular-schema-form, and ran into a problem that when I load a schema and a form from a server using REST, the validation sometimes did not kick in. I could post a schema even though some fields were required.
How can I always be sure that the required fields in the form has to be filled in by the user before posting?
I found that using $scope.$broadcast('schemaFormValidate'); before submitting the form works (from the docs).
$scope.onSubmit = function(form) {
// First we broadcast an event so all fields validate themselves
$scope.$broadcast('schemaFormValidate');
// Then we check if the form is valid
if (form.$valid) {
// ... do whatever you need to do with your data.
}
}
However, we can not disable any buttons beforehand.
#John you can set a value in your model that is part of a display condition. That allows you to hide the buttons on submit and then re-enable them when you are ready for the user to submit the form again for any reason.
When my field becomes invalid, is there a way to fire a method in my js?
So for example, the user fails to fill out the name field, clicks submit, I want to:
console.log('they forgot');
Thanks
There is a $error object made available by AngularJS. This object contains all of the validations on a particular form and tells if they are valid or invalid.
To get access to this property, we can use the following syntax:
formName.inputfieldName.$error
Here is a jsfiddle sample
This document is a good reference for understanding form-validations using AngularJS.
Also, for dealing with custom validations, you can add your own directives. A sample of making such directives is given in the link above.
I have a form and when the user hits submit, I want to be able to display a message "Are you sure you want to do this"? and if they hit yes, I want it to be submitted?
Thanks
You can use this code in your view
echo $this->Form->create('FormName',array(
'type'=>'file','onsubmit'=>'return confirm("are you sure?");')
);
automatically in cake there is not direct solution for a button as it is for a link :S though you may do it with javascript.
Here is a code for it using jquery for the events asuming your button id is "submit"
$(document).ready(function() {
$('#submit').click(function() {
return confirm('You sure you want to continue?');
});
});
With this you are done, just load this js into your page and change it to please your needs :D hope this helps you
I am going to implement paypal in cake php. I have two conditions to post the form.
Fist posts the form to paypal, if user click on paypal button. Then form shoud be posted at paypal url at : https://www.paypal.com/cgi-bin/webscr .
If user click on submit button form should be posted to it controller.
It means i want to create two forms at a single page and want to posts at different places in certain conditions.
If I am giving custom action in form, it is adding app name+controller name before the url. like: appname/controllername/http://google.com. but want only http://google.com .I want to remove appname/controllername from the url.
How do I do this? Thanks in advance.
In your form creation call, you need to specify the URL
echo $this->Form->create('Model', array('url' => 'http://google.com'));