x-editable drop down from remote not working - drop-down-menu

I am using X-editable bootstrap version 2
I am using codeigniter . But the text area and text box is working fine for me but drop down is not working .
in my view
< a href="#" id="contract" data-type="select" data-pk="1" data-source="<?php echo base_url('property/contract_get_update')?>" data-title="Select Contract type" class="" >contract data </a>
$( document ).ready(function() {
$('#contract').editable();
});
in my controller
public function contract_get_update()
{
echo "{'M': 'male', 'F': 'female'}";
}
i just tested with this output not working i tried many tricks but it is not seems to be working.
i want to display details from table name contract how can i get that value as a drop down in x-editable

I answered you on gitHub too. The problem is with your json format.
Try this:
$contract_types = array();
$contract_types[] = array('value' => 'M', 'text' => 'male');
$contract_types[] = array('value' => 'F', 'text' => 'female');
echo json_encode($contract_types);
If you are looping through a db query of results try this in your function:
foreach($results AS $result){
$json_response[] = array('value' => $result['id_column'], 'text' => $result['your_column']);
}
echo json_encode($json_response);

You need to use a custom class with text and value members (case sensitive) to enumerate it as a List of type this class then use it to response after ajax call.

Related

How to get tinybutstrong mergeblock with condition working for empty value

I am using tinybutstrong as a templating engine.
I am trying to get the active link to display in a different color.
The following is my (trimmed down) PHP side:
$links = array (
'' => 'Home',
'about' => 'About Us',
'faq' => 'FAQ',
'contact' => 'Contact Us',
);
$uri = substr($_SERVER['REQUEST_URI'], 1);
$TBS->MergeBlock('blkLinks', 'array', $links);
Html Template:
<ul>
<li>[blkLinks.val;]</li>
</ul>
While it generates the html fine and nicely changes the color of the links when that page is currently active, this does not work for the empty (/) link.
How can I fix that?
Simply replace the condition
[onload.uri]=[blkLinks.$]
with
'[onload.uri]'='[blkLinks.$]'
The point is that when [onload.uri] is an emprty string, then the expression can be ambiguous. Using the string delimitors, the expression is clear for TBS.

How to add new columns in group price section in magento

I need to add 2 new columns in magento admin in the group price section.
I have checked the template file.
app/design/adminhtml/default/default/template/catalog/product/edit/price/group.phtml
I have added new columns there, but..
how can i add these two columns in database and save values.
Any suggestions?
Thanks.
I've had the same issue. Answer by Samuel Coman was great help for me. To be more precise, you have to modify three files. I have added integer column 'popularity' (to be used by xml-rpc methods), but rules are the same. Here is my example.
The first file
magento/app/design/adminhtml/default/default/template/catalog/product/edit/price/group.phtml
in table around line 50 add new <th>:
<th><?php echo $this->getPriceColumnHeader(Mage::helper('catalog')->__('Popularity')); ?></th>
in var groupPriceRowTemplate around line 67 add new <td>:
+ '<td><input class="<?php echo $_htmlClass; ?>" type="text" name="<?php echo $_htmlName; ?>[{{index}}][popularity]" value="{{popularity}}" id="group_price_row_{{index}}_popularity"/></td>'
in var groupPriceControl line 95 modify default arguments etc.:
var data = {
website_id: '<?php echo $this->getDefaultWebsite(); ?>',
group: '<?php echo $this->getDefaultCustomerGroup(); ?>',
price: '',
popularity: '',
readOnly: false,
index: this.itemsCount++
};
if(arguments.length >= 3) {
data.website_id = arguments[0];
data.group = arguments[1];
data.price = arguments[2];
data.popularity = arguments[3];
}
if (arguments.length == 5) {
data.readOnly = arguments[4];
}
add your column in addItem call, line 165:
groupPriceControl.addItem('<?php echo $_item['website_id']; ?>', '<?php echo $_item['cust_group']; ?>', '<?php echo sprintf('%.2f', $_item['price']); ?>', '<?php echo sprintf('%.0f', $_item['popularity']); ?>', <?php echo (int)!empty($_item['readonly']); ?>);
The second file
magento/app/code/core/Mage/Catalog/Model/Product/Attribute/Backend/Groupprice/Abstract.php
here you have to modify afterSave method, firstly add your column to the array $new, line 316:
$new[$key] = array_merge(array(
'website_id' => $data['website_id'],
'all_groups' => $useForAllGroups ? 1 : 0,
'customer_group_id' => $customerGroupId,
'value' => $data['price'],
'popularity' => $data['popularity'],
), $this->_getAdditionalUniqueFields($data));
then you have to handle a case when you only change your new column and save it, so on line 349, after if (!empty($update)) statement, goes:
if (!empty($update)) {
foreach ($update as $k => $v) {
if ($old[$k]['price'] != $v['value'] || $old[$k]['popularity'] != $v['popularity']) {
$price = new Varien_Object(array(
'value_id' => $old[$k]['price_id'],
'value' => $v['value'],
'popularity'=> $v['popularity'],
));
$this->_getResource()->savePriceData($price);
$isChanged = true;
}
}
}
The third file
magento/app/code/core/Mage/Catalog/Model/Resource/Product/Attribute/Backend/Groupprice/Abstract.php
here modify loadPriceData method to properly show values from database; you have to just add your column to $colums variable, line 49:
$columns = array(
'price_id' => $this->getIdFieldName(),
'website_id' => 'website_id',
'all_groups' => 'all_groups',
'cust_group' => 'customer_group_id',
'price' => 'value',
'popularity' => 'popularity',
);
There is no need to change savePriceData method, as _prepareDataForTable inside it will find your new columns in database.
Than you have to add your columns to group prices table and also to tier price table, because it uses the same save methods, so run in mysql on your database commands similar to the following:
alter table catalog_product_entity_group_price add popularity integer;
alter table catalog_product_entity_tier_price add popularity integer;
And last, but not least remember to refresh the cache - without doing this system won't find new columns.
Hope it will help someone.
To add the column create a new module and inside the installer alter the table catalog_product_entity_group_price and add your desired columns.
To save & display the data...well, I hope you are pretty advanced of Magento overriding.
The file you mentioned takes some data from Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Group_Abstract but the real data is taken using the loadPriceData from Mage_Catalog_Model_Resource_Product_Attribute_Backend_Groupprice_Abstract
The prices are saved in method afterSave from Mage_Catalog_Model_Product_Attribute_Backend_Groupprice_Abstract which calls savePriceData from Mage_Catalog_Model_Resource_Product_Attribute_Backend_Groupprice_Abstract
You could try to override those methods but you might break some Magento stuff. Those prices are tied with the Indexers also. Another option would be to create a separate module, to add another observer on product save, save your data into a separate table and get it back using an extension of Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Group_Abstract

Cakephp with Ajax, this.element.setAttribute is not a function

I'm trying to make a stackoverflow like tags system.
I followed this tutorial (in French): http://www.formation-cakephp.com/34/autocomplete-en-ajax which uses Prototype and Scriptaculous. Of course, I adapted it to my project
I get the following error:
this.element.setAttribute is not a function : controls.js Line 86
which corresponds to
this.element.setAttribute('autocomplete','off');
in the control.js file
I'm really new to Ajax, so I don't have a clue on what I'm doing (wrong)...
If you need some code from any file, let me know!
view.ctp:
<div class="input">
<label>Tags :</label>
<?php e($ajax->autoComplete(
'Tag.tag',
'/tags/autocomplete',
array(
'minChars' => 3,
'indicator' => 'ajaxloader'
)
)); ?>
<div id="ajaxloader" style="display:none;">
Chargement...
</div>
Controller:
function autocomplete()
{
$recherche = utf8_decode($this->data['Tag']['tag']);
$tags = $this->Tag->find(
'all',
array(
'fields' => 'DISTINCT tag',
'conditions' => "tag LIKE '$recherche%'",
'order' => 'tag',
'limit' => 10
)
);
$this->set(compact('tag', 'recherche'));
}
jQuery, scriptaculous, & prototype don't play well together but you can resolve this issue by putting jQuery in no-conflict mode.
var $j = jQuery.noConflict();
// $j is now an alias to the jQuery function; creating the new alias is optional.
Now instead of using the $ to for jQuery use $j so for example:
$j(document).ready(function() {
$j( "div" ).hide();
});
For more information on avoiding jQuery conflicts refer to the following: https://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/
It appears that scriptaculous doesn't play well with j-query. When I removed the j-query link I stopped getting an error. This definitely isn't an ideal solution, but I thought I'd share my discovery.

Drupal Webform Validation (webform_form_alter)

I'm doing some webform validation using webform_form_alter. I'm using webform_form_alter because I switch certain content on a "select" field.
In my webform-form-317.tpl.php I defined new fieldsets I set my fields into this new fieldset and unset the original from the webform.
$form['submitted']['ContactInfo'] = array(
'#type' => 'fieldset',
'#prefix' => '<div id="ContactInfo">',
'#suffix' => '</div>',
'#weight' => -10,
'#title' => 'Contact Information'
);
$form['submitted']['ContactInfo']['phone_home'] = $form['submitted']['phone_home'];
unset($form['submitted']['phone_home']);
in my webform_form_alter I have the following code:
switch ($form_id)
{
case 'webform_client_form_317':
{
$form['#validate'][] = 'validate_form';
}
}
My Validate_form function looks like:
function validate_form($form_id, $form_values)
{
if ($form_values['submitted_tree']['ContactInfo']['phone_home'] == "")
{
form_set_error('phone_error', t('Please enter a home phone number.'));
}
}
The issue is that the $form_values['submitted_tree']['ContactInfo']['phone_home'] comes back as nothing even is the user has inputted something into the textfield.
Any suggestions on what i'm doing wrong?
As a second question in case somebody also the answers, how do I modify the of these textfields to set the class for "form-text required error" so they show up in red with the rest of the mandatory fields.
Thanks
I hope you don't write this code in the webform module, but have made your a custom module for it.
In the first case, your function should be
function validate_form($form, &$form_state) {
if ($form_state['values']['submitted_tree']['ContactInfo']['phone_home'] == "") {
form_set_error('phone_home', t('Please enter a home phone number.'));
}
}
If you are talking about the error class, Drupal add it to all fields that has an error set like is done on the above code. You need to pass in the name of the form field as first param to the form_set_error function.

Cakephp 1.3, Weird behavior on firefox when using $this->Html->link

Greetings,
I am getting a very weird and unpredictable result in firefox when using the following syntax:
$this->Html->link($this->Html->div('p-cpt',$project['Project']['name']) . $this->Html->div('p-img',$this->Html->image('/img/projects/'.$project['Project']['slug'].'/project.thumb.jpg', array('alt'=>$project['Project']['name'],'width'=>100,'height'=>380))),array('controller' => 'projects', 'action' => 'view', $project['Project']['slug']),array('title' => $project['Project']['name'], 'escape' => false),false);
OK I know it is big but bear with me.
The point is to get the following output:
<a href="x" title="x">
<div class="p-ctp">Name</div>
<div class="p-img"><img src="z width="y" height="a" alt="d" /></div>
</a>
I'm not sure if this validates correctly both on cakephp and html but it works everywhere else apart from firefox.
You can actually see the result here: http://www.gnomonconstructions.com/projects/browser
To reproduce the result use the form with different categories and press search. At some point it will happen!!
Although most of the time it renders the way it should, sometimes it produces an invalid output like that:
<div class="p-cpt">
name
</div>
<div class="p-img">
<img src="x" width="x" height="x" alt="x" />
</div>
Looks like it repeats the link inside each element.
To be honest the only reason I used this syntax was because cakephp encourages it.
Any help will be much appreciated :)
I am guessing that the name of some projects is null. According to the documentation, if you pass null as the second argument to the div() method, it will not generate the closing tag (and the resulting markup will be invalid).
The example of invalid markup that you pasted above appear to have come from Firebug rather than Page Source. Use Page Source to view the actual markup sent to the browser. The anchor tag is not repeated.
I rewrote your code to better see what happens. Copy it into one of your views, change 'My Project' to null, and notice how it will affect the $name_div variable:
<div class="p-cpt">My Project</div> will turn into <div class="p-cpt">.
<?php
$project['Project']['name'] = 'My Project';
$project['Project']['slug'] = 'my-project';
$image = $this->Html->image(
'/img/projects/' . $project['Project']['slug'] . '/project.thumb.jpg',
array(
'alt' => $project['Project']['name'],
'width' => 100,
'height' => 380
)
);
$name_div = $this->Html->div('p-cpt', $project['Project']['name']);
$image_div = $this->Html->div('p-img', $image);
$link = $this->Html->link(
$name_div . $image_div,
array(
'controller' => 'projects',
'action' => 'view',
$project['Project']['slug']
),
array(
'title' => $project['Project']['name'],
'escape' => false
)
);
var_dump($image);
echo 'Notice what happens below if project name is null.';
var_dump($name_div);
var_dump($image_div);
var_dump($link);
echo $link;

Resources