why don't set the placeholder attribute for contact field? - drupal-7

this is my code that use in hook_form_alter function for set the placeholder attribute:
if ($form_id == 'contact_site_form') {
$form['name']['#title'] = t('name/family name');
$form['name']['#attributes']['placeholder'] = t('Enter your name');
}
why don't set the placeholder attribute for contact field?

I added this line to code and the problem was solved:
$form['name']['#default_value'] ='';
Edited code is:
if ($form_id == 'contact_site_form') {
$form['name']['#title'] = t('name/family name');
$form['name']['#default_value'] ='';
$form['name']['#attributes']['placeholder'] = t('Enter your name');
}

Related

Disable checkboxes that will appear empty when filtering

Link to the filter:
code: http://jsfiddle.net/ar3PY/92/
Question:
I can filter and I will get result "empty"
But how to disable checkboxes that will anyway appear empty when filtering.
!!Notice that each category shall no filter with itself, only with other categories.
For example:
If I check "VOLVO" and "SILVER" I get "empty".
What I looking for:
If I check "VOLVO", then "SILVER" will be disabled.
Image that show how it should work:
Basically you just needed to access your class attributes to make it work. I forked your fiddle, here's the modified version:
$("#filters :checkbox").click(function() {
var subj = this;
resetBoxes();
$(".filterme").show();
if(this.checked){
var all = $(".filterme");
var tgts = all.filter(getFilter("brand")).filter(getFilter("class")).filter(getFilter("color"));
var brandtgt = tgts[0].className.split(' ')[1];
$("#filters :checkbox").each(function(idx){
var inval = $(this).attr("value");
var brandclasses = tgts[0].className.split(' ');
var found = $.inArray(inval, brandclasses);
if(found<0){
disable($(this));
}
});
all.not(tgts).hide();
tgts.show();
if (tgts.length == 0) {
$('.empty').show();
} else {
$('.empty').hide();
}
}
});
I've included helper functions (resetBoxes, enable, disable) found in the working fiddle below.
http://jsfiddle.net/ppzwmvs9/6/
How to show content of checked filter that only has exacly same attribute for each category?
see also image for explanation:
.
JSFIDDLE HERE:
http://jsfiddle.net/ar3PY/104
.
var getFilter = function (category) {
var filter = $("#filters ." + category + ":checked").map(function () {
return '[data-filter*="' + this.value + '"]';
}).get().join(",");
filter = (filter.length > 0) ? filter : "*";
return filter;
}

How to reset a registration form in angular js

I'm facing one issue with a registration form.
If I log in and browser offers me to save username/password, they are both displayed on the registration form.
I tried to reset the form, I tried to set user details to null, but it didn't work.
As username and password are predefined, repeat password error is present.
here is a snap
Register Controller
...
registerController.$inject = ['$location', 'UsersService', '$timeout'];
function registerController($location, UsersService, $timeout) {
var vm = this;
vm.master = {};
vm.isValid = false;
vm.error = false;
vm.errorMessage = "";
vm.user = {
username : '',
password : '',
email: ''
}
formReset();
// function to submit the form after all validation has occurred
vm.submitForm = function(isValid) {
// check to make sure the form is completely valid
if (isValid) {
console.info('form valid');
vm.isValid = true;
}
if(vm.isValid === true){
signup();
}
else{
vm.error = true;
vm.errorMessage = "All fields are required";
}
};
function signup() {
// initial values
vm.error = false;
vm.success = false;
var username = vm.user.username;
var password = vm.user.password;
// call register from service
UsersService.register(username, password)
// handle success
.then(function () {
vm.success = true;
vm.successMessage = "Registrations successful.You'll get confirmation email soon and you can proceed with login";
$timeout(function() {
$location.path('/login');
}, 5000);
})
// Catch error
.catch(function (fallback) {
vm.error = true;
vm.errorMessage = fallback;
});
};
function formReset(form){
if(form === '' || form === undefined){
form = vm.form;
}
if(form){
form.$setPristine();
form.$setUntouched();
form.$setValidity();
}
vm.contact = angular.copy(vm.master);
}
}
jade template
form.form-horizontal.col-md-12(name="form" role="form", data-ng-submit="ctrl.submitForm(form.$valid)", method="post" novalidate, autocomplete="off")
.form-group(show-errors)
label.control-label.col-xs-3 Username
span.icon-req.glyphicon.glyphicon-asterisk
.col-xs-9
input.form-control(type="text", name="username", placeholder="Enter Username", data-ng-model="ctrl.user.username", data-user-id="{{ctrl.user._id}}", data-ng-minlength="3", required="required" auth-username)
span.help-inline.error(data-ng-show = "form.$dirty && form.username.$error.required") Username required
span.help-inline.error(data-ng-show = "form.$dirty && form.username.$error.minlength") Username too short
span.help-inline.error(data-ng-show = "ctrl.form.username.$touched && ctrl.form.username.$error.usernameExists") Username already taken
.form-group(show-errors)
label.control-label.col-xs-3 Password
span.icon-req.glyphicon.glyphicon-asterisk
.col-xs-9
input.form-control(type="password", name="password", placeholder="Password", data-ng-model="ctrl.user.password", data-ng-minlength="6",ng-maxlength="16", required="required")
span.help-inline.error(data-ng-show = "form.$dirty && form.password.$error.required") Password required
span.help-inline.error(data-ng-show = "form.$dirty && form.password.$error.minlength || form.password.$error.maxlength") Password must be 6-16 character long
.form-group(show-errors)
label.control-label.col-xs-3 Repeat password
span.icon-req.glyphicon.glyphicon-asterisk
.col-xs-9
input.form-control(type="password", name="repeatPassword", placeholder="Repeat Password", data-ng-model="ctrl.user.repeatPassword", data-ng-minlength="4",required="required", equal-to="ctrl.user.password")
span.help-inline.error(data-ng-show = "form.$dirty && form.repeatPassword.$error.equalTo") Password must be equal
....
button.btn.btn-default(type="submit") Submit
a(href='/')
button.btn.btn-primary(type="button") Cancel
I'm pretty much new to mean stack development, and I'm sure I miss something out.I appreciate your help. Thanks
PS: the code posted is a simplified and not optimized one
So first I try with the HTML autocomplete Attribute. But it was not working on chrome. After that I found this post Chrome Browser Ignoring AutoComplete=Off.
One of the solution to disable autocomplete is to set the input readonly and add a bit of js on the onfocus Attribute.
onfocus="this.removeAttribute('readonly')
I test this solution with an angular form and it's working.
See the original fiddle by fizzix

update one field of a table from another controller while save the data

I have a manage_returns_controller and it has two action,add and index.It has one product dropdown,one stock dropdown and add button.And I also have manage_products_controller that contains a field stock.But now I want to do the following
When I click on the returns controller's add button then simultaneously save the return data as well as increase the stock in the product table.
heres the add action code
function add($id = null)
{
/*$this->pageTitle = "Edit Exchange";*/
$storeval = $this->Store->find('all',array('conditions'=>array('is_deleted'=>0,'is_blocked'=>0)));
//$storeval=$this->Store->findByName();
$storevalas = array();
foreach($storeval as $storevall)
{
$storevalas[$storevall['Store']['id']] = $storevall['Store']['name'];
}
$this->set('stock_entry_option_store', $storevalas);
//$product_name = $this->Exchange->product->find('list');
$storevaldd = $this->Product->find('all',array('conditions'=>array('is_deleted'=>0,'is_blocked'=>0)));
//$storeval=$this->Store->findByName();
$product_name = array();
foreach($storevaldd as $storevall)
{
$product_name[$storevall['Product']['id']] = $storevall['Product']['name'];
}
$this->set('stock_entry_option_product',$product_name);
$this->Return->id = $id;
if(!empty($id)){
$button_name = "Update";
$msg_act = "updated";
$this->pageTitle = "Edit Return";
} else {
$button_name = "Add";
$msg_act = "added";
$this->pageTitle = "Add Return";
}
if (empty($this->data))
{
$this->data = $this->Return->read();
}
else
{
if ($this->Return->save($this->data))
{
$this->Session->setFlash(__('Return successfully '.$msg_act.'.',true),'default',array('class' => 'success'));
$this->redirect(array('controller'=>'ManageReturns','action' => 'index'));
}
}
$this->set('button_name',$button_name);
}

Clearing fields with angular?

When the user clicks on a radio button I run:
$scope.clientClick = function() {
//do stuff
}
I have a form, and I would like half of the fields on the form to be cleared in the above method.
I have done:
$scope.clientClick = function() {
$scope.entry.first_name = '';
$scope.entry.last_name = '';
$scope.entry.email = '';
$scope.entry.tel = '';
$scope.entry.gender = '';
$scope.entry.job = '';
$scope.entry.age = '';
}
But is there an easier way rather than listing each field again?
Short answer
['first_name', 'last_name', ...].forEach(function (f) {
$scope.entry[f] = '';
});
Long answer
In JavaScript, properties can be accessed in two ways:
obj.prop
obj['prop']
You can keep a list of strings with the properties that you want to clear, and then just iterate over it clearing each in turn.
I'd suggest that if you have a dependency to the radio button then the view model should reflect that it could be cleared:
$scope.entry.dependant = { first_name: '' ... }
$scope.clientClick = function() {
$scope.entry.dependant = {};
}
function initObject(obj) {
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
switch(typeof obj[i]){
case 'string':
obj[i] = '';
break;
case 'number':
obj[i] = 0;
break;
}
}
}
}
Use this function. NEVER do this $scope.entry = {} or $scope.entry.name = null, it's safer and you won't get unnecessary errors when you have some parts of your code that expect a type. It's a lot easier just to set a string to "".
I would use $scope.entry = null or $scope.entry = {}.
Make code simple and readable.
I would have done some thing like Reset a model with angular.js:
$scope.initial = [
{
first_name : '',
last_name : '',
email : '',
tel : '',
gender : '',
job : '',
age : ''
}
];
Demo
$scope.clientClick = function() {
angular.copy($scope.initial, $scope.entry);
});

How to define a checkbox variable in Cakephp

I have a form in my Plugin elements and what i would like to insert the checkbox value into a table named it_queries and field status_type and its giving me an error Undefined variable: variableValue [APP\Plugin\Feedback\View\Elements\comment_add.ctp, line 37] .I have declared the variable in my controller like this
$this->set('variableValueStatus', 'Pending');
and this is line 37 thats giving me the error
Below is the Controller code
App::uses('FeedbackAppController', 'Feedback.Controller');
class CommentsController extends FeedbackAppController
{
public $components = array('Feedback.Comments');
public function add($foreign_model = null, $foreign_id = null)
{
if (empty($foreign_model) ||
empty($foreign_id) ||
!$this->request->is('post')
)
{
foreach ($_POST['likebutton'] as $pageId => $likeFlag) {
$dbFlag = $likeFlag ? 'Yes' : 'No';
}
return $this->redirect('/');
}
App::uses($foreign_model, 'Model');
$Model = ClassRegistry::init($foreign_model);
if (!($Model instanceof Model))
{
return $this->redirect('/');
}
if ($Model->hasAny(array($Model->primaryKey => $foreign_id)) == false)
{
return $this->redirect('/');
}
if (!isset($this->request->data['Comment']['foreign_model']) ||
!isset($this->request->data['Comment']['foreign_id']) ||
$this->request->data['Comment']['foreign_model'] != $foreign_model ||
$this->request->data['Comment']['foreign_id'] != $foreign_id)
{
return $this->redirect('/');
}
$user_id = null;
if (isset($this->Auth))
{
$user_id = $this->Auth->user('id');
}
$this->request->data['Comment']['foreign_model'] = $Model->name;
$this->request->data['Comment']['foreign_id'] = $foreign_id;
$this->request->data['Comment']['user_id'] = $user_id;
$this->Comment->create();
if (!$this->Comment->save($this->request->data))
{
$this->set('validation_errors', $this->Comment->validationErrors);
return;
}
$this->redirect($this->request->referer().'#comment-'.$this->Comment->id);
}
}
and in the add view in my element here is how i am trying to accessing the variable value
echo $this->Form->checkbox('ItQuery.status_type', array('type' => 'hidden', 'value'=>$variableValueStatus));
If someone can show me how to fix this, that would be awesome
You are only passing the variable down on !post and if foreign model and foreign id are not set.
That will most likely not work in most of the cases.
You should be always passing down a variable if you do not check on it in the view prior to using it.
But it would still be wrong, anyway. You would have to use "default" instead of "value" if you dont want your form to fall back on the old value on POST (which it shouldnt).
Also, it is always better to use $this->request->data to properly fill the form with defaults:
if (!$this->request->is('post')) {
$this->request->data['ItQuery']['status_type'] = 'Pending';
}
See working-with-forms

Resources