Undefined variable: lang laravel - variables

I got a problem the file cannot find the variable 'lang'.
{{ Form::open(['action' => 'loon.language']) }}
{{Form::select('lang',['nl'=>'nl','po'=>'po'], $lang,['onchange'=>'submit()'])}}
{{$lang = 'blaat'}}
{{var_dump($lang)}}
{{ Form::close()}}
Controller:
public function postChangeLanguage()
{
$rules = [
'language' => 'in:nl,po' //list of supported languages of your application.
];
$language = Input::get('lang'); //lang is name of form select field.
$validator = Validator::make(compact($language),$rules);
// $language = Session::get('language',Config::get('app.locale'));
if($validator->passes())
{
Session::put('language',$language);
App::setLocale($language);
}
else
{ /**/ }
}
Route:
Route::get('language', array(
'uses' =>'LoonController#postChangeLanguage',
'as' => 'loon.language'
));
Filter.php:
App::before(function($request)
{
$language = Session::get('language','nl'); //en will be the default language.
App::setLocale($language);
});
Ill even tried to debug it and still this error code!
Undefined variable: lang (View: /Users/nielsvandijk/loon/rekentool/app/views/partials/header.blade.php) (View: /Users/nielsvandijk/loon/rekentool/app/views/partials/header.blade.php)
Can someone help?

The first time you are using $lang it is still empty apparently..
A quick fix would be to use an # sing in front of it (allowing it to be undefined)
{{Form::select('lang',['nl'=>'nl','po'=>'po'], #$lang,['onchange'=>'submit()'])}}
The purpose of the lang variable is to define the "selected" element in the select field
{{Form::select('lang',['nl'=>'nl','po'=>'po'], 'po',['onchange'=>'submit()'])}}
This would result in:
<select name="lang">
<option value="nl">nl</option>
<option value="po" selected="selected">po</option>
</select>
In the controller you could set the default language if no language is preselected
View::make('view')->with('lang','nl');

Related

Correct way to implement drill-down tags in vue with vuetify

I am using a v-chip-group with v-chips to represent a tag cloud for records in my database. I have an object array with records that look something like { key:'device', count:100}. A record could have multiple tags, so as you click on a tag, a new query is made that filters on that tag, the result will then have a new tag cloud with a subset of the previous.
It looks something like this:
tag1 (1000), tag2 (100), tag3 (100)
When you click on tag1 you end up with:
tag1 (1000), tag3 (15) (no tag2 because there is no overlap between tag1 and tag2).
Here is the relevant template code:
<v-chip-group v-model="selectedTag" multiple #change="refresh">
<v-chip v-for="tag in tags" :key="tag.key" active-class="primary">
<v-avatar left class="grey">{{ tag.count }}</v-avatar>
{{ tag.key }}
</v-chip>
</v-chip-group>
The problem I have is that in the typescript I do something like this:
refresh() {
// get simple array of tag strings
const selectedTags = this.selectedTag.map((value: any) => {
if (this.tags && this.tags[value]) {
return this.tags[value].key
} else {
return null
}
}).filter((value: any) => {
return value != null
})
Promise.all([
...
ApiCall('GET', 'tags', {limit: 1000, tags: selectedTags}),
...
).then((values) => {
// decode response from server into new tags
this.tags = values[2].series['0'].values.map((item: any) => {
return {key: item.bucket, count: item.doc_count}
})
const newTags: number[] = []
this.tags.forEach((tag, index) => {
// find the new index of the previously selected tags and save them
if (selectedTags.find(st => {
return st === tag.key
})) {
newTags.push(index)
}
})
// update selectedTag with the new value
this.$set(this, 'selectedTag', newTags)
// did not work this.selectedTag = newTags
})
}
What I'm seeing is that when I click a chip, it correctly fires the #change event and calls refresh, but then when the refresh finishes, I see an additional refresh get called with an empty selectedTag, which clears my filters and recalls the above functionality.
Is there a way to get #change to fire when a chip is changed, but not fire (or filter it out) when the event is generated by changing the data referenced by v-model?

Kendo-vue-ui wrapper kendo-grid-column format phone number in grid

I have been trying to use vuejs filter in kendo-grid-column
<kendo-grid-column field="phone" title="Phone" :template="`kendo.toString(phone) | phoneformat`" width="10%"></kendo-grid-column>
Rather being displayed as formatted string the result is displayed as
Filter I am using as:
const filters = [
{
name: "phoneformat",
execute: value => {
debugger
var piece1 = phoneNumber.substring(0, 3); //123
var piece2 = phoneNumber.substring(3, 6); //456
var piece3 = phoneNumber.substring(6); //7890
//should return (123)456-7890
return kendo.format("({0})-{1}-{2}", piece1, piece2, piece3);
}
}
];
export default filters;
I have been registering the filter globally as:
import filters from './shared/extension'
filters.forEach(f => {
Vue.filter(f.name, f.execute)
})
Help me what i am missing here.
:template="`kendo.toString(phone) | phoneformat`"
You have backticks around the :template attribute value, meaning you're binding the template prop to a JavaScript template literal which evaluates to the literal string
"kendo.toString(phone) | phoneformat"
The solution is to simply bind an expression instead
<kendo-grid-column :template="phone | phoneformat" ...
See
https://v2.vuejs.org/v2/guide/filters.html
https://v2.vuejs.org/v2/guide/components-props.html#Passing-Static-or-Dynamic-Props

prestashop 1.7 add a field to checkout process (and save it)

Good day, I've created a module that adds a new field (ask for invoice) during the checkout, I've added it in the payment selection hook.
How I save the field value (it is a checkbox) once the page is submitted? I mean after a payment is been selected and the submit button is pressed?
public function hookDisplayPaymentTop()
{
/*
echo"<pre>";
print_r($this->context->cart);
echo"</pre>";
*/
$sql = 'SELECT vat_number FROM ' . _DB_PREFIX_ . 'address WHERE `id_address` = '.$this->context->cart->id_address_invoice;
$vat_number = Db::getInstance()->getValue($sql);
if ($vat_number == false) {
$message = $this->l(' your VAT number is invalid or ');
$vat_status = 0;
}else{
$message = $vat_number;
$vat_status = 1;
}
$this->context->smarty->assign([
'foo' => 'bar',
'usrId' => $this->context->customer->id,
'vat' => $vat_number,
'vat_status' => $vat_status,
'cartId' => $this->context->cart->id
]);
return $this->display(__FILE__, '/views/templates/front/doyouinvoice.tpl');
}
and the TPL is like:
<h5>Do you need an invoice?</h5>
<div class="ggAskInvoiceError {if $vat_status == 1}hideThisMessage{/if}">
{l s="You need to add your VAT number in the billing address." m="ggaskinvoice"}
</div>
<div class="ggAskContainer">
<label><input type="checkbox" name="askInvoice" id="askInvoice" {if $vat_status == 0}disabled='disabled'{/if} data-cartid="{$cartId}" > {l s="I need an invoice for this order" m="ggaskinvoice"}</label>
</div>
Maybe try to use Tools::isSubmit
I'm not sure if this can work for you,
Try to create a controller in your module like this: in yourModule/controller/controllerName,
class yourModuleNameModuleFrontController extends ModuleFrontController
{
public function initContent(){
parent::initContent();
$this>setTemplate('module:yourModuleName//views/templates/front/doyouinvoice.tpl');
if(Tools::isSubmit('askInvoice')){ //askInvoice is your name button
//Your php code
}
}
}
And for the DisplayHook i think you only need to do this
return $this->display(__FILE__, '/views/templates/front/doyouinvoice.tpl');

How can I add 2 condition in one class vue.js 2?

My vue component is like this :
<template>
<a :class="'btn ' + [respond == 'responseFound' ? ' btn-yellow' : ' btn-default', type == 1 ? ' btn-block' : ' btn-xs center-block']">
...
</a>
</template>
I try like that, but it does not work?
You can use :class="[array, of, classes]" syntax:
<a :class="['btn', (respond === 'responseFound' ? 'btn-yellow' : 'btn-default'), (type === 1 ? 'btn-block' : 'btn-xs center-block')]">
As a bonus you don't have to worry about adding the leading spaces, Vue will handle it.
Just to keep things clean in view/template/markup, move your conditions to computed properties:
<template>
<a :class="['btn', getRespondClass, getTypeClass]">
</template>
<script>
export default {
data () {
return {
respond: '',
type: ''
}
},
computed: {
getRespondClass () {
return this.respond === 'responseFound' ? 'btn-yellow' : 'btn-default'
},
getTypeClass () {
return this.type === 1 ? 'btn-block' : 'btn-xs center-block'
}
}
}
</script>
Pretty sure the current showed answer says how you can add multiple classes on 1 condition. But if you want to have multiple conditions for your class added you can simply just do it like this:
:class="{'classname': condition_one && condition_two}"
Or you can do this:
:class="[ condition1 | condition2 ? 'className' : '']"
This checks for either of the conditions to be true. If you want to check for both replace | with &&. But if you have nothing in the else class, I think #Marnix's answer is cleaner.

Angular Translate default translate value while using filter

Is there any way to provide the translate-default value while using the filter instead of directive?
e.g:
How to achieve the same results as this
<h3 translate="TEST" translate-default="Not present"></h3>
with filter format
{{ 'TEST' | translate }}
How do i put the "translate-default" attribute when using the translate filter?
What i need to do is show the original text if the key is not present.
I have created a wrapping filter for that purpose:
.filter('txf', ['$translate', ($translate: angular.translate.ITranslateService) => {
return (input: string, stringIfNotAvailable: string = '') => {
const translation = $translate.instant(input);
return translation === input ? stringIfNotAvailable : translation;
};
}]);