Firstly I'm new to Laravel and this is my first post. Please forgive me if I'm doing things wrong.
I have an HTML table, which is a Livewire component. In this HTML table, each row has a dropdown box and some text fields. This is for a timesheet application. The dropdown is the job and there are 7 text boxes, for each day of the week for the hours to be entered.
I have tried to include an Add button, I want this to add a new row at the end of the HTML table.
The issue I'm getting is when I click on Add, it will append the row, however, my dropdown is not shown, UNTIL I refresh the page, then it appears as it should.
The way I currently have my program is that when a user clicks on add, it will create a new record in my Entries table, with the timesheet ID included, and the rest of the values as null. Is there another way of temporarily storing the lines the user creates, then commit to the database? Is there a way to refresh my table so that it displays the new line correctly?
Please let me know if you need further details or a better explanation of my issue.
My code is as follows:
Controllers\Livewire\ShowTimesheet.php
...
public function mount($entries)
{
$this->entries = $entries;
}
public function render()
{
return view(‘livewire.show-timesheet');
}
public function add($i)
{
$entries_new = new Entries;
$entries_new->timesheet_id = $i;
$entries_new->save();
$new = array(
'id'=>$entries_new->id,
'timesheet_id'=>$i,
'job_id'=>null,
'worktype_id'=>null,
'hours_sun'=>null,
'hours_mon'=>null,
'hours_tue'=>null,
'hours_wed'=>null,
'hours_thu'=>null,
'hours_fri'=>null,
'hours_sat'=>null,
);
$this->entries[] = $new;
}
...
Layouts\livewire\show-timesheet.blade
...
#foreach($timesheet as $sheet)
...
<div wire:click="add({{$sheet['id']}})" class='cursor-pointer'>
...
#endforeach
...
Related
my problem is when I try to edit one of the records in my KeyController it not only edit record that I want but all the records connected by local_id. Variable $local is only for redirecting to previous page to show all the keys.
I want to change type, quantity and intercom password. id_klucza after request is correct.
public function potwierdzenie_edycji_kluczy(Request $request,$id_klucza)
{
$klucze = klucze::where('id_klucza','=', $id_klucza)->first();
$klucze->typ_klucza = $request->typ_klucza;
$lokal=$klucze->id_lokalu;
$klucze->ilosc_kluczy = $request->ilosc_kluczy;
$klucze->kod_domofon = $request->kod_domofon;
$klucze->save();
return redirect('lista_kluczy/'.$lokal);
}
Can you tell me what I'm doing wrong and what I can do to edit only one record I want no everything connected to it?
I created Dynamic fields for billing information,item name,qty,rate,total fields are loaded dynamicall by click Add New.When i want to update active records in dynamic fields there some Database Error.
Any For loop issue or anyone suggest--Cheers!
public function updatebill(){
$currentBillId=$this->input->post('bill_no');
$update_billno=$this->input->post('itemData[1[bill_no]');
$updatePostData=$this->input->post('itemData');
$this->load->model('billmodel');
$this->billmodel->update_bill_details($currentBillId,$updatePostData);
}
I have checked $cuurentBillId(having bill Id),$updatePostData(having input fields data which i want to update on the table)
public function update_bill_details($currentBillId,$updatePostData){
$bill_no=$this->input->post('itemData[1[bill_no]');
$item_name=$this->input->post('itemData[1][item_name]');
$item_quantity=$this->input->post('itemData[1][item_quantity]');
$item_rate=$this->input->post('itemData[1][item_rate]');
$item_total=$this->input->post('itemData[1][item_total]');
$item_tax=$this->input->post('itemData[1][item_tax]');
$without_tax=$this->input->post('itemData[1][without_tax]');
$item_grand_total=$this->input->post('itemData[1][item_grand_total]');
$item_income_tax=$this->input->post('itemData[1]item_income_tax');`for($i=1;$i<sizeof($updatePostData); $i++)`
{
$result=array(
'item_name'=>$item_name,
'item_quantity'=>$item_quantity,
'item_rate'=>$item_rate,
'item_total'=>$item_total,
'item_tax'=>$item_tax,
'without_tax'=>$without_tax,
'item_grand_total'=>$item_grand_total,
'item_income_tax'=>$item_income_tax);
$this->db->where('bill_no',$i);$this->db->set($result[$i]);
}
Currently I have a refno. column in my database with the format LP00001. Now I have a add page that inserts all data that the user inserts in the input field and all this data gets sent to a table in my database, but my refno column stays null which I want to have an auto incrementing value where the last 5 digits will be +1 everytime the user submits the form.
I do not want to have it be shown before the submit button as 2 users can be on that page at the same time which means they both will get the same id which means it has to generate it only at the time of submit. Currently this is my code:
Controller class:
if ($this->form_validation->run() == FALSE)
{
$main['page'] = 'crm/listings/add';
$this->load->view('crm/index', $main);
}else {
$maindata=array('clients_id'=>$this->session->userdata('clientsessid'),
'property_for'=>$this->security->xss_clean($this->input->post('property_for')),
'property_type'=>$this->security->xss_clean($this->input->post('property_type')));
$insertid=$this->listings_model->insert_listing($maindata);
if($insertid){
$this->session->set_flashdata('message', '<div>Successfully</div>');
redirect('listings/sales');
Model Class:
function insert_listing($maindata){
$this->db->insert("crm_listings",$maindata);
$prime=$this->db->insert_id();
return $prime;
}
So I assume I'll need to do this in my model class function insert_listing since that is called when I press submit button. Here another thing will be that the model will have to check what was the last entry in the database that has to be incremented for which I'm assuming I'll have to use echo str_replace("LP","","LP00001");
I guess you just have to prepend the initials LP to the returned autoIncremented id.
function insert_listing($maindata){
// ...
$this->db->set("refno", "LP". sprintf('%05d', $prime));
$this->db->where('id', $prime);
$this->db->update("crm_listings");
return $prime;
}
Is there a way to create/update form poll fields based on a content type? For example, I've got a post type called Candidate and I'd like like to dynamically update a poll list when a new Candidate is added, or when one is removed.
The reason I'm looking for this is because I'm creating a voting mechanism for this client and they have requested that users see an image, the name, and brief Bio of who they are voting for. My idea is to tie in the names so that I can target a hidden Gravity Form poll on page so when the voter clicks, it updates the corresponding named checkbox.
I can of course add each Candidate one by one, and then add each candidate one by one in the form, but was hoping there was a way to do that in code. So far I haven't found much other than filters in the Gravity Forms Documentation.
To reiterate, my question here is not the frontend connection, rather how to dynamically update/add an option in a poll field in a form when content is created for a Candidate post type.
Any help would be appreciated.
I believe the solution you're after is documented here:
http://www.gravityhelp.com/documentation/gravity-forms/extending-gravity-forms/hooks/filters/gform_pre_render/
Probably a combination of solution examples #1 and #2 on that page will fit your needs? So -
Create a category of standard Wordpress pages (category name: "Candidates"), and the pages would contain the candidate information (bio, photo, etc).
In your functions.php file for your current theme, you'd add something like the following to pull out that category's worth of posts:
// modify form output for the public page
add_filter("gform_pre_render", "populate_checkbox");
// modify form in admin
add_filter("gform_admin_pre_render", "populate_checkbox");
function populate_dropdown($form) {
// some kind of logic / code to limit what form you're editing
if ($form["id"] != 1) { return $form; }
//Reading posts for "Business" category;
$posts = get_posts("category=" . get_cat_ID("Candidates"));
foreach ($form['fields'] as &$field) {
// assuming field #1, if this is a voting form that uses checkboxes
$target_field = 1;
if ($field['id'] != $target_field) { break; }
// init the counting var for how many checkboxes we'll be outputting
// there's some kind of error with checkboxes and multiples of 10?
$input_id = 1;
foreach ($posts as $post) {
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
if($input_id % 10 == 0) { $input_id++; }
// here's where you format your field inputs as you need
$choices[] = array('text' => $post->post_title, 'value' => $post->post_title);
$inputs[] = array("label" => $post->post_title, "id" => "{$field_id}.{$input_id}");
// increment the number of checkboxes for ID handling
$input_id++;
}
$field['choices'] = $choices;
$field['inputs'] = $inputs;
}
// return the updated form
return $form;
}
I'm new to yii and I don't understand the extensions much
but I used this extension called jmultiselect2side because I'm trying to make a site where users could reserve stuff like apparatuses in the lab
Anyway, I need a code that would get the Selected Items and then display them in another page for viewing purposes
I haven't put anything in the controller but the name of my controller and model is Apparatus
Here is my view:
<?php
$model= Apparatus::model()->findByAttributes(array('ApparatusCode'=>'1'));
// complete user list to be shown at multiselect order by ApparatusCode
$Apparatus= Apparatus::model()->findAll(
array('order' => 'ApparatusCode'));
?>
<center>
<?php
$this- >widget('application.extensions.jmultiselect2side.Jmultiselect2side',array(
'model'=>$model,
'attribute'=>'ApparatusName', //selected items
'labelsx'=>'Available',
'labeldx'=>'Selected',
'moveOptions'=>false,
'autoSort'=>'true',
'search'=>'Search:',
'list'=>CHtml::listData( // available items
$Apparatus,
'ApparatusCode',
'ApparatusName'),
));
?>
please help as soon as possible :/
put all above elements in a form. Set action for the form. Submit the form then the action in which you are handling this submit request, you can write there
if(isset($_POST))
{
foreach($_POST['Apparatus']['ApparatusName'] as $name)
{
do what ever you want
}
}
$name will represent the each selected item