I am completely lost for two days and have no clue how to fix this nonsense!
I use fileinput widget in my page like this:
echo FileInput::widget([
'name' => 'attachment_product[]',
'id' => 'img_products',
'options' => [
'multiple' => true
],
'pluginOptions' => $pluginOptions,
]);
In the same page i have a button that when clicked, reloads the content with renderAjax.
On success i reload the content like this:
$('.content').html(data);
The problem is that the fileInput widget is not being initialized.. I dont know what to do and i get this error:
fileinput_516a5cfe is not defined
As i read here: https://github.com/kartik-v/yii2-widgets/issues/229 and here: https://github.com/kartik-v/yii2-widget-switchinput/issues/14. I need to reinitialize the plugin but I have no clue how to do that... I am lost..
This is by design, A JavaScript file would typically only need loading once so all subsequent requests filter out already included files.
If you want to load it with every request you can add it's path to yii.reloadableScripts yii.js
https://github.com/yiisoft/yii2/issues/10251
Related
I am using a cakephp 2.5 postlink method inside a view file :
$tableRow['Model.modelatribute'] = $this->Form->postLink(
$data['Vehicle']['plate'],
array('controller'=>'somecontroller',
'action' => 'somemethod',
'Model.modelatribute' => base64_encode($data['Vehicle']['plate'])
),
array('confirm' => 'Look at vehicle '.$data['Vehicle']['plate'])
);
I would like not to show the model atribute name on the url bar. After clicking on the link and being redirected, the url shows :
somemethod/Model.modelatribute:vSpEeTIweQ%3D%3D
Can i hide the model atribute name, using postlink method o cakephp 2.5 ?
Thank´s in advance
If you simply want to pass the value of Model.modelatribute as a parameter, just leave off Model.modelatribute in your routing array. If you want to pass the value without occouring in the url you can use the data option of postLink.
echo $this->Form->postLink(
$data['Vehicle']['plate'],
array(
'controller'=>'somecontroller',
'action' => 'somemethod',
base64_encode($data['Vehicle']['plate']) // Routing array without modelname
),
array(
'confirm' => 'Look at vehicle '.$data['Vehicle']['plate'],
'data' => array(
// Data option of postLink method
'Model.modelatribute' => base64_encode($data['Vehicle']['plate'])
)
)
);
Well, you put in there. If you don't want it to be there simply don't put it in the URL. You can alternatively put it into the body of the POST request.
If you're concerned that people can use the model name for something and you want to hide it for that reason, then it is a very bad approach called security through obscurity. Instead you want to ensure that you validate that only values you want are passed and processed. So check your incoming data, always, from everywhere.
I have a module, which includes multistep form. I decided to make one of these steps work like this: free times per employee are rendered as html elements, and when element is clicked, Javascript will apply the value to hidden input field.
So I found this tutorial: http://drupal.org/node/1092122 but it didn't work for me, maybe I made a error, maybe not.
My module name is reservation. My template file is named reservation_select_time_week_page.tpl.php and its in the reservation/theme folder.
I have these functions:
function reservation_theme() {
// basic things
$module_path = drupal_get_path('module', 'reservation');
$base = array(
'path' => "$module_path/theme",
);
// define themes
return array(
'reservation_select_time_form' => $base + array(
'render element' => 'form',
'template' => 'reservation_select_time_week_page',
),
);
}
function template_preprocess_reservation_select_time_week_page(&$variables) {
echo "this works!";
}
function template_preprocess_select_time_form(&$variables) {
echo "this works!";
}
I dont know which of those preprocess functions is right (should it be named based on template name or form id?
Anyhow, custom template is not applying.
I also have tried using the:
$form['start_time'] => array('#theme' => 'reservation_select_time_week_page');
I got it working, so that the static html is rendered in template file, but I dont know how I can render the form elements in template file. Using:
drupal_render($form)
caused the form to go infinite loop I think.
Is Drupal even able to handle complex forms and form layouts?
I have CakePHP website I want to display Google map and marker in given address on my CakePHP application.
Is there any plugin available to display address in Google map.
You probably did not even try to google.
Or you would have stumpled upon at least a dozen plugins/solutions.
Check this one out:
http://www.dereuromark.de/2010/12/21/googlemapsv3-cakephp-helper/
// include jquery js
$this->Html->script('jquery', array('inline' => false));
// include the google js code
$this->Html->script($this->GoogleMapV3->apiUrl(), array('inline' => false));
// echo the div container to display the map in
echo $this->GoogleMapV3->map(array('div'=>array('height'=>'400', 'width'=>'100%')));
$options = array(
'lat' => 48.95145,
'lng' => 11.6981,
'title' => 'Some title', // optional
'content' => '<b>HTML</b> Content for the Bubble/InfoWindow' // optional
);
$this->GoogleMapV3->addMarker($options);
// finalize js
$this->GoogleMapV3->finalize();
// Make sure you got `echo $this->Js->writeBuffer(array('inline' => true));` somewhere in your layout then
If you do not have the lat/lng yet, you can either geocode via JS at runtime or use Cake to do so: http://www.dereuromark.de/2012/06/12/geocoding-with-cakephp/
You can also use CakePHP-GoogleMapHelper that will geocode the address on the fly and add it to your map. You would do something like this: (see more details on the link shared)
<?= $this->GoogleMap->addMarker("map_canvas", 1, "1 Infinite Loop, Cupertino, California"); ?>
I'm searching for a way to add a field in a custom form that will allow me to upload a list of files like this one : which is a screenshot of a File field of the file module.
I tried this : http://ygerasimov.com/d7-zip-archive-custom-file-multiple-upload
which uses ajax and custom code. My files are saved in DB but not displayed when I reload the page... I tried to make it work but with no luck.
I really hope that someone will be able to help me.
Thanks in advance,
Hervé
You can used this for custom multiple upload fields:
$form['file'] = array(
'#type' => 'file',
'#name' => 'files[]',
'#title' => t('Upload some photos'),
'#description' => t('JPG\'s, GIF\'s, and PNG\'s only, 10MB Max Size'),
'#attributes' => array('multiple' => 'multiple'),
);
I wanted to now if there is a way to pass a simple string inside url and cakephp some how put it inside one of the inputs of my form without any code writing on view side?
I tried calling this->set("bla","bla"); the field name is bla
but nothing changed in view
As I understood the question you want to have something like this:
in the url you have something like:
http://yourserver.com/controller/action?search=string
and you want to put this "string" in the search field, right?
Then let's imagine that your field's name is data[search_field]. (I am skipping the model, because for my example it's not needed, but it's possible the name to be data[Model][search_field]).
Then in your controller's action you have to do following:
$this->data['search_string'] = $this->params['url']['search'];
You can pass values in the url by using html helper. Try:
echo $this->Html->link('View Some Page', array(
'controller' => 'yourController',
'action' => 'view',
1, // id
'?' => array('yourField' => 'valueToPass'))
);