Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am unable to get select2() working as desired. I want a dropdown has (a) a placeholder to say "Select From Currency" and (b) to be searchable.
I have the following codeigniter code. mh_xrate_currency is the 3 letter value for the currency like USD, AUD, CAD, EUR, etc. mh_xrate_name is the name like United States Dollars, Australian Dollars, Canadian Dollars, Euro, etc.
<div class="row">
<div class="form-group col-lg-6 col-md-6">
<?php
$options = array();
$options[0] = null;
foreach ($currencies as $currency) {
$options[$currency['mh_xrate_currency']] = $currency['mh_xrate_currency'].', '.$currency['mh_xrate_name'];
}
$attributes = 'class="form-control input-md xrate_from_dropdown" ';
echo form_dropdown('xrate_from', $options, set_value('xrate_from'), $attributes);
?>
</div>
</div>
The above code produces a page like following;
<div class="row">
<div class="form-group col-lg-6 col-md-6">
<label for="mh_xrate_currency">Xrate From a</label>
<select name="xrate_from" class="form-control input-md xrate_from_dropdown" >
<option value="0"></option>
<option value="BRL">BRL, Australian Dollar</option>
<option value="AUD">AUD, Australian Dollar</option>
<option value="GBP">GBP, British Pound</option>
<<snip>>
</select>
</div>
</div>
I also have the select2 loaded and have the following code;
$(document).ready(function () {
$(".xrate_from_dropdown").select2({
placeholder: "Select From Currency...",
allowClear: true,
});
});
but for some strange reason, the page initially displays as;
initial-display
Notice the x in the above image below the dropdown. Then after selected, it displays as follows;
[
I forgot to load the select2 css files!! arrg. When I load the css files, it works well.
Related
when the user click add more and submit their form data, I'm having a problem saving form array like this (service[], Amount[], Description[]) in database rows. I have two related tables of invoices and invoice_details, i want the form array to submit the list of form data into the invoice_details table. I have successfully created the models and relations between the invoice and invoice_details.
<!--Blade -->
<div class="service-box">
<div class="row">
<div class="col-md-12 service-group">
<div class="row">
<div class="form-group mb-3 col-md-6">
<label class="form-label">Service</label>
<div >
<select type="text" class="form-select" placeholder="Services" value="" name="service[]" id="service">
<option value="" disabled selected>Select your option</option>
#foreach ($services as $service)
<option value="{{$service->service_name}}" data-id="{{$service->amount}}">{{$service->service_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group mb-3 col-md-6">
<label class="form-label">Amount</label>
<div >
<input type="text" class="form-control" name="amount[]" id="amount" placeholder="Amount" readonly>
</div>
</div>
<div class="form-group mb-3 col-md-12">
<label class="form-label">Description</label>
<textarea class="form-control" id="description" name="description[]" rows="6" placeholder="Description.." ></textarea>
</div>
</div>
</div>
</div>
</div>
//Controller
$invoicedetailModel = new Invoice_detail;
//Here is where the problem lies, I have to save for arrays.
$invoicedetailModel->service = request('service');
$invoicedetailModel->amount = request('amount');
$invoicedetailModel->description = request('description');
$invoiceModel->Invoice_details()->save($invoicedetailModel);
It seems to me (correct me if I'm misinterpreting) that you're trying to save a batch of different InvoiceDetails and attach them to an original Invoice model.
The problem here is that you're trying to do so by passing arrays to a single invoiceDetails model so let's suppose you have the you have two detail instances passed by form you would have the request parameters structured like this:
$request->service: ['serviceX','serviceY']
$request->amount: [1,2]
$request->description: ['Lorem', 'Ipsum']
So if you tried to create the model you're trying to save in your code you would be doing something like this:
Invoice_Details::create([
'service' => ['serviceX', 'serviceY'],
'amount' => [1,2]
'description' => ['Lorem', 'Ipsum']
]);
Which can not work because those values are not set as Json to the database, and also explains why the createMany is not working, because there's a single object that uses an array of values for each value. What you might want is a situation like this:
Invoice_Details::createMany([
[
'service' => 'serviceX',
'amount' => 1
'description' => 'Lorem'
],
[
'service' => 'serviceY',
'amount' => 2
'description' => 'Ipsum'
]
]);
So you should iterate the request parameters and save a whole array of single models rather than try to stuff everything into a single one.
Also, it's pretty legitimate to ask yourself "Sure, but they all have two parameters, why doesn't it just split them when I use the createMany method?" Well, let's suppose the same situation with different parameters:
$request->service: ['serviceX','serviceY']
$request->amount: [1,2]
$request->description: ['Ipsum']
To which model does that description belong to? We could just go by appearence order, but this kind of assumption might lead to huge problems in case of bad implementations. This sadly means that everytime we need to create multiple models we need to define every single one, even though it means adding an iteration beforehand.
TL;DR: Instead of an array of parameters you need an array of models. Iterate through your parameters and build your models before saving them.
//Supposing you already fetched the arrays and they are all of the same length
$details = [];
foreach($services as $key => $service) {
$invoicedetailModel = new Invoice_detail();
$invoicedetailModel->service = $services[$key];
$invoicedetailModel->amount = $amounts[$key];
$invoicedetailModel->description = $descriptions[$key]);
$details[] = $invoicedetailModel;
}
// code to create and attach the many models
Hi Im struggling to get the value of each radio button groups. The functions is about getting answers from different questions.
{{form.answer_ids}}
<div v-for="ans in answers" :key="ans.id">
<div v-if="ans.question_id == question.id">
<div class="p-2 border rounded border-secondary m-2" >
<input
style="cursor:pointer;"
class="form-check-input m-2"
type="radio"
:name="ans.question_id"
:value="ans.id"
v-model="form.answer_ids"/>
<h5 class="ml-4 p-1" v-html="ans.description"> </h5>
</div>
</div>
</div>
<script>
data() {
return {
form: this.$inertia.form({
answer_ids:[]
}),
}
},
</script>
When there is v-model, the radio is not grouping yet returning only 1 value (not array), On the other hand, When I Remove v-model, The grouping is working but unable to get the data.
How can i possibly achieve this? Just taking the checked radio answer ids is enough for me.
Thank you very much and have a good day!
I have a form for creating a question with multiple(as many as one wishes) possible answers. Here is the picture:
The code for a single possible answer:
<div class="input-group">
{{-- Checkbox for the answer --}}
<span class="input-group-addon">
<input type="checkbox" name="answer[0][is_correct]" value="1">
</span>
{{-- Input field for the answer --}}
<input type="text" class="form-control" name="answer[0][body]">
{{-- . . . --}}
</div>
I need to validate that, there exist at least three answers for a question and at least one of them is correct. How can I achieve this?
I would consider separating your answer text fields from your answer checkboxes for the sake of clarity.
Below hasn't been tested - but something like the following should hopefully help you along?
$numAnswers = count($input->only('answers_text'));
$rules = [
'answers_checked' => 'array|min:1|max:' . $numAnswers,
'answers_text' => 'array|min:3|required',
'answers_text.*' => 'required|string',
];
$v = Validator::make($input, $rules);
if ($v->fails()) {
return response()->json($v->errors(), 422);
}
...
I want to display a list of ALL suppliers available in the order detail page in a select box and all suppliers available for that product in another select box.
What I tried to do is add to \prestashop\admin\themes\default\template\controllers\orders\helpers\view\view.tpl:
<div class="form-group">
<label for="id_supplier" class="control-label col-lg-3">{l s='Supplier'}</label>
<div class="col-lg-9">
<div class="col-lg-8">
<select id="id_supplier" name="id_supplier">
{foreach from=$suppliers item='supplier'}
<option value="{$supplier.id_supplier}">{$supplier.name}</option>
{/foreach}
</select>
</div>
</div>
</div>
But this doesn't work (the select box is empty).
there's no $supplier in controllers/admin/AdminOrdersController.php which means that you need to get informations about Suppliers by using this code:
$suppliers = Supplier::getSuppliers();
of course you need to foreach this loop and check which supplier is already in order and create another array for second select
after that you need to assign those variables in renderView method in controller
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Im seriously jealous of the person who designed this website and in particular the 'info' bar at the top of the page that notifies you every so often.
I very much want this on my website, does anyone know of a downloadable script that resembles something like this? (php)
An answer from the stackoverflow design team would be nice! ;)
This will largely be done with jQuery. It's just a matter of periodically querying the server:
setInterval(function(){
$.post("getUpdates.php", function(response){
showInfoBar(response);
});
}, 10000);
That would request updates every 10 seconds. You could do this once the page loads too. As for the PHP code in getUpdates.php:
if (!isset($_SESSION["userid"]))
die("You are not logged in");
$updates = getUpdatesForUser($_SESSION["userid"]);
if ($updates) {
print json_encode($updates);
} else {
print "No updates";
}
As for the get-updates, you can do that as a table in your database:
userid | time | updatemsg
-------------------------------------------------------------
28 | 2009-08-21 12:53:02 | You've received the 'uber' badge.
Getting a users updates is as easy as querying this table for all new updates. You could create a field to indicate when an update has been sent, and should not be sent again.
This is all very thrown-together, but should give you a very basic idea of how to accomplish it.
View -> Source
<div id="topbar">
<div id="hlinks">
<img src="http://sstatic.net/so/img/replies-off.png" width="15" height="10" title="you have no new replies">
<a href="/users/144496/martin" >Martin</a> <span class="reputation-score" title="reputation score">741</span><span title="9 bronze badges"><span class="badge3">●</span><span class="badgecount">9</span></span>
<span class="link-separator">|</span>
logout
<span class="link-separator">|</span>
about <span class="link-separator">|</span> faq
</div>
<div id="hsearch">
<form id="search" action="/search" method="get">
<div>
<input name="q" class="textbox" tabindex="1" onfocus="if (this.value=='search') this.value = ''" type="text" maxlength="80" size="28" value="search">
</div>
</form>
</div>
</div>
Then check out the CSS.
It's a million times easier than it looks.
You just use jQuery, have a div that is width 100%, left : 0; top : 0; and then show it with some jQuery animation function.
You can achieve the same functionality with jQuery framework.
Its really easy to do.