I want to auto-populate data in text-boxes for in VUE. I have this set of array.
[
{"ID":"1","Name":"JOHN DOE","Email":"JohnDoe#GMAIL.COM","Phone Number":"58656","Address":"Somewhere"},
{"ID":"2","Name":"JANE ZOE","Email":"JohnDoe#GMAIL.COM","Phone Number":"9969","Address":"Anywhere"},
{"ID":"3","Name":"JENNY JAMES DOE","Email":"JJames#GMAIL.COM","Phone Number":"888888","Address":"Everywhere"}
]
CODE PEN https://codepen.io/hiro-john/pen/jOOwwza?editors=1010`
If anyone select, 'JOHN DOE' from the Dropdown Name , his details should be auto-populate to the respective fields which are 'Email, Phone & Address' from the Array List. User can add more than 1 Person and each Person data should populate base on 'Name' Dropdown.
Used this function to search inside the Array.
function indexWhere(array, conditionFn) {
const item = array.find(conditionFn)
return array.indexOf(item)
}
And bind the value on Select Change Event.
const index = indexWhere(items, item => item.Name === name)
this.shareholders[id].Address = items[index].Address;
this.shareholders[id].Email = items[index].Email;
this.shareholders[id].Phone = items[index].Phone;
Updated CODE PEN https://codepen.io/hiro-john/pen/jOOwwza?editors=1010
Related
I have a function called updateAnswer with multiple dynamic parameters.
updateAnswer(key, answer, array = false) {
if (array) {
if(this.answers.contains.find(element => element === answer)) {
//Delete item from array if already element already exists in this.answers.contains array.
} else {
Vue.set(this.answers, key, [...this.answers.contains, answer]);
}
} else {
Vue.set(this.answers, key, answer);
}
},
I'd like to know how delete an item in the array if the value already exists in the array.
You can use method called splice:
Just reference on your array and set values in the brackets the first is referenced on the position, the second is how many datas you want to splice/delete.
The function looks like this:
this.array.splice(value, value)
Lets see on an example - you have array food= [apple, banana, strawberry] than I'm using this.food.splice(1,1)..
my array looks now like this food = [apple, strawberry] - first value in my brackets are the position, the second one is the amount of "numbers" you want to delete.
Hopefully this helps you out!
I suppose each value in this.answers.contains is unique?
Anyways, if you just want to delete the item if already exists, I suggest filter(). It should look like below:
if(this.answers.contains.find(element => element === answer)) {
this.answers.contains = this.answers.contains.filter(c => c !== answer)
}
Also, the if condition if(this.answers.contains.find(element => element === answer)) could also be replaced by if(this.answers.contains.includes(answer))
Hope that could help you.
I am populating Gravityforms fields using the functions.php from my template and it works like a charm, but I have one field that is ... a challenge. I have been able to populate the choices from my database just fine, but with the functions.php I cannot control the content of the display area of the field so that I can, for example, add a title or header for each category. Is there a way to programattically adjust the display here's an example of what im hoping to accomplish
RadioButton Choice (Field ID 21)
Dark Colors (category title)
maroon (choice 1)
navy blue (choice 2)
black (Choice 3)
Standard Colors (Category Title)
Red (choice 4)
blue (choice 5)
gray (Choice 6)
Light Colors )Category Title)
pink (choice 7)
sky blue (choice 8)
white (Choice 9)
I am just looking for a way to add the category title between the choices. My DB Query has the categories as part of the response, but the only option I have to populate choices to to feed an array.
I have seen where I can add additional Gravityform fields and have them controlled by the same "single select" radio button option, but the categories involved change based on the DB query I call to dynamically populate the choices and could range from 1 category to 10, which will not have correlating fields in the form itself, as this is all under a single radio-button field.
Any thoughts would be appreciated.
I was able to use the link I posted in my comment to provide a solution. As part of my "choices"
here is the function for the Pre-Render to populate choices. In this case I am populating a radio-button field with product images instead of default radio buttons
add_filter('gform_pre_render_1', 'populate_choices');
function populate_choices($form) {
global $wpdb;
// Now to get a list of the products I want to include on this radio-button
$dataQ = "
SELECT category, product_id, product_name
FROM product_table
WHERE product_type = 'whatever I am looking for'
ORDER BY category, product_name ASC
";
$dataR = $wpdb->get_results($dataQ);
$dataList = array();
// get current protocol to use in Product Images
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
// Rebuild URL for use with product image graphics
$productImageUrl = $protocol.$_SERVER['HTTP_HOST'].'/wp-content/product_images/';
// Generate list of choices for the radio-button, along with category headers
foreach ($form['fields'] as $field) {
if ($field->id == '32') { // 32 My specific radio-button field
$category = "";
foreach ($dataR as $data) {
if ($category != $data->category) {
// If I hit a new category, add the "header" item to the "choices" list with a unique search item to identify it, in this case "###"
$category = $data->category;
$dataList[] = array(
'text' => '#'.$category."#",
'value' => ''
);
}
$productImage = str_replace(" ","",strtolower($data->product_name)).".jpg";
$productID = $data->product_id;
$dataList[] = array(
'text' => $data->product_name,
'value' => $productID,
'isSelected' => false,
'price' => '0.00',
'imageChoices_image' => $productImagehUrl.$productImage
);
}
$field->choices = $dataList;
}
}
}
I then added a specific field modifier to update the "#category#" choice elements with html to make the category names show up.
// numbers after filter = "1" for form ID 1, "32" for field ID 32
add_filter('gform_field_choice_markup_pre_render_1_32', function( $choice_markup, $choice) {
if ( strpos( $choice['text'], '#' ) === 0 ) {
$categoryName = str_replace("#","",$choice['text']);
$choice_markup = '
<li style="width:100%;text-align:left;">
<span style="color:#000000;font-weight:bold;font-size:18px;">
<br>
'.$categoryName.'
</span>
</li>
';
}
return $choice_markup;
}, 10, 2);
can i just have listdata by itself? The list doesn't list anything, all I keep getting is "Array" as the return.
I have:
$awards= $model->findAll('uid='.$uid);
return CHtml::listData($awards, 'award_id', '$data->award->name');
try this code:
$awards= $model->findAll(array('condition'=>'uid ='.$uid)); // get records from table
return CHtml::listData($awards, 'award_id', 'award_name'); // third parameter should the array value. Most of the case we use to display in combo box option text.
If you are getting from another table, then declare a variable in your award model.
public $awrd_name;
Then you have to get records using relation in criteria.
Output will be :
array("1" => "award1", "2" => "award2", "3" => "award3");
refer this link : http://www.yiiframework.com/forum/index.php/topic/29837-show-two-table-fields-in-dropdownlist/
I don't really know how to deal with the next issue :
So, I've a webbased application developped with ASP.NET MVC3, which is used to remember when an event is relayed to some people.
I've 3 tables
Contact
id_contact
name
firstname
...
event
id_event
...
transmission
FK_id_event
FK_id_firstname
mailed (boolean)
phoned (boolean)
For each event, I need to list all the contacts that are related to this event. And for each contact, I need to display 2 checkboxes that have to be checked if the contact has been called or mailed.
'
' GET: /Event/Details/5
Function Details(id As Integer) As ViewResult
Dim event As event = db.event.Single(Function(o) o.idOpportunite = id)
Dim contacts = (From a In db.contact, b In db.transmission
Where a.id_Contact = b.FK_id_contact And b.FK_id_event = id
Select a)
Dim transmission = (From a In contacts, b In db.transmission
Where a.id_Contact = b.FK_trans_cont
Select b)
Dim model = New EventDetails With {
.event= event,
.Contacts = contacts,
.TransOpp = transopp
}
Return View(model)
End Function
I don't know if the "transmission" part of the code is good or not.
Here in the view, this is were I display the contacts
#For Each contact In Model.contacts
#<tr>
<td>
#Html.ActionLink(contact.name + " " + contact.firstname , "Details", New With {.id = contact.idContact})
</td>
<td>
#Html.Raw(contact.phone)
</td>
<td>
#*Html.DisplayFor(Function(modelItem) currentItem.mail)*#
<a href=mailto:#contact.mail>#Html.Raw(contact.mail)</a>
</td>
<td>
***My checkboxes should be here***
</td>
</tr>
Next
So, my question is, what should I do to display those checkboxes?
(sorry if I'm not understandable, I'm not a native english speaker. Don't hesitate to edit my english mistakes (or the title which is not a great one)).
With the help of Yasser, I've done this :
#code
Dim mail As Boolean = (From a In Model.Event
Where a.FK_id_contact = contact.idContact And a.FK_id_event = Model.Opportunite.idOpportunite
Select a.mailed)
End Code
However, I get an error :
Value of type 'System.Collections.Generic.IEnumerable(Of Boolean)' cannot be converted to 'Boolean'.
Here is something that should help
#{
bool isMailed = // set values;
bool isPhoned = // set values
}
#Html.CheckBox("mailed ", isMailed );
#Html.CheckBox("phoned", isPhoned );
In your ContactViewModel you can have two properties
bool isMailed ;
bool isPhoned ;
Then you can query the database from your controller before you bind the viewmodel the view and set those parameters. For example if you are showing data for contact id = 1 and event id = 2, you can query the database table transmissions and find whether you have called or mailed before and update the variable in ContactViewModel.
then in your view you can bind the values to the checkbox as follows
#Html.CheckBox("mailed ", contact.isMailed );
#Html.CheckBox("phoned", contact.isPhoned );
if you want to update the mailed or phoned in the database you can do it using the above ViewModel by submitting data to the controller. from controller you can find what is the Event_Id, Contact_Id and mailed or phoned , then you can update the database accordingly
My problem is:
I would like to get all advertistments where id of Description column is equals with Advertistment's column.
Let's say that Advertistment column is connected with Description column.
I would like to gain all description's id where one of its column called type_of_house is equals m.
Then show all advertistment where advertistment's id is equals with description's id.
In short way: advertistment shows info about houses, descriptions store houses type D and M and I want show all advertistments with houses type of M.
This is correct sql:
SELECT * FROM advertistment, description WHERE advertistment.id_advertistment = description.id_description AND description.type_of_house = "m"
I have no idea how write it into zend. I tried something like that. This function I wrote in model folder.
public function takeAll() {
$select = $this->_db->select();
$select->from(array('a' => 'advertistment', 'd' => 'description'));
$select->where('a.id_advertistment = d.id_description AND d.type_of_house = m');
return $select->query()->fetchAll();
}
You're actually quite close. This should work:
public function takeAll() {
$select = $this->_db->select();
$select->from(array('a' => 'advertistment'));
$select->join(array('d' => 'description'), 'a.id_advertistment = d.id_description');
$select->where('d.type_of_house = ?', 'm');
return $this->_db->fetchAll($select);
}