CakePHP omitting to send an input field and changing input value onSubmit? - javascript

I am on CakePHP 1.2 at the office and, following my last question, I would like to send the array key of the selected option in a SELECT input instead of sending its actual value. I have tried a few things with the Model::beforeSave() function, without success.
I am aware that the data posted by CakePHP does not include the whole array, but only the selected value.
Here is what the function looks like at the moment:
function beforeSave(){
$this->Post->set('category_id', = array_keys($this->data['Annonce']['category_id']);
# debug($this->data);
}
Would there be a way to store the array keys into an hidden input and changing this input value depending on the user's selected item in the SELECT input, and to also omit sending the user's input but still send the hidden value?

$categories = Set::combine($categories,'{n}.categories.id', '{n}.categories.nom');
This did it for me... CakePHP assigns the array_keys() values automatically to the value field of the input.

Related

How to get the field values using the Modified javascript step in pentaho?

I'm trying to get the field values and field meta data ie., field properties,
Using the following script I'm able to find the field type and field properties. Now im trying to check if there is any null value in the a particular field, so that I can replace the field value with the default values based on the field type.
How can I read the field values without using the input fields ie.,hard coding (ie., to use some inbuilt functions as of how we get the meta data)following is the snip of code that i used to get the field properties

Trying to grab the 'save' from a dropdown option from a clone in Bootstrap and save the input to Local Storage

trying to save the input provided from the user in an input form that is cloned, so i want it to work for all the 'save' options, keep that text in local storage, and lastly to maintain that text in the input form even when the user refreshes the page, i've tried a bunch of different ways at my wits end, ha. here is fiddle: https://jsfiddle.net/dalejohn33/24u3vxmp/13/
$save.click((f) => {
var task = $("input:selected").val();
var getTask = JSON.parse(localStorage.getItem("input"));
var setTask = JSON.stringify(localStorage.setItem("input"));
console.log("text input has been saved");
}
thanks for any help!
There are some tasks here:
Get the right input's value
var task = $(f.target).closest('.dropdown-menu').next().val();
$(f.target).closest('.dropdown-menu') gets you to the dropdown and the input is next() to it.
localStorage.setItem accepts 2 arguments: (1) The key name (2) The data (You pass only the key).
In order to set the input's value to the value stored in localStorage, you need to store each input as a different key (not just input).
You need to iterate the inputs and set its value from localStorage.
Since the value you store is string, you don't need to stringify / parse.
Another point is the inconsistency name and id. The first element (the one you clone later) has none. Also the id and name are different values because you increase it between (length++)
https://jsfiddle.net/moshfeu/kw8jfg1m/32/

JSON user search

I have the following gist with a JSON database and an XHR object.
The user parameter from getUsers(user) method is an input value.
I want select an user from the db via input search value. But i don't know how to set the http url or the searching algorithm.
I can select an user via: user.Name1 but how can i modify the entries after the dot .Name1 so it can be selected with the input value.
E.g: user. + "input value". I can't figured out.
I hope I inderstood you right, you want to access it via square brackets:
user[userValue] where userValue is your input variable
You can access on object like this user["Name1"] and as such can do this : user[input_value_variable]

Not able to store the value of 2nd drop down in servlet using request.getParameter

I have 2 dropdowns. The 2nd dropdown is populated according to what I select on the first. In my form 2nd drop down came automatically after select 1st one using ajax in java.But my problem is I can't store the value of 2nd drop down in servlet like 1st drop down using request.getParameter
You can easily get whatever selected in drop-down by request.getParameter()
String first = request.getParameter("first");
String second = request.getParameter("second");
One possible solution is, you can try
Enumeration paramNames = request.getParameterNames();
to get all possible parameters from your form. Then iterate through among them to get your required values based on parameter names.

change value of input text field

That's the html for the input field:
<input id="sku_input_field" type="text" name="items[0<?php echo $uniqueSuffix; ?>][sku]" class="input-text" />
And the javascript code that I am trying:
$('sku_input_field').value = jsonResponse.sku;
document.getElementById("sku_input_field").value = jsonResponse.sku;
So, you see, I am trying 2 approaches, and it doesn't work. I use FireBug to check and the response is NOT empty. I can see all the values that I am setting into it. The value of the field though still remains the same as the one I am typing.
It is that I type an id, and when the object with that id is found in the database I return a json response with some values (this happens in PHP). And one of these values, in the json response, is the one I want to set as a new value of the input field.
The value of the sku attribute is what I want to set as value of the input field. As you see, the response is not empty.
Should be :
jQuery
$('#sku_input_field').val(jsonResponse.sku);
// Provided jsonResponse.sku is not empty
// Also make sure jquery library is added.
Pure Javascript :
document.getElementById('sku_input_field').value = jsonResponse.sku;
p.s : Please check whether you are using same ID for any other element. ID needs to be unique.

Categories