laravel livewire mount dynamic fields - laravel

I would like to have dynamic input fields with values ​​for all that are already entered in the db.
the following code works!
here the values ​​of the input extras.4 fields are displayed on the website
public function mount() {
$this->advettisment_extras = DB::table('advertisment_extras')
->where('advertisment_number', '=', $this->advertisment['advertisment_number'])
->where('user_id', '=', Auth::user()->id)->get()->toArray();
foreach ($this->advettisment_extras as $advettisment_extra) {
$this->extras = [
'4' => '12346548'
];
}
}
but when I try to dynamically search for and fill in the fields from db, the values ​​are not displayed.
foreach ($this->advettisment_extras as $advettisment_extra) {
$this->extras = [
$advettisment_extra->extra_id => $advettisment_extra->extra_value
];
}
can anyone help ?

<div class="row" wire:init="loadExtras">
#if(isset($categorie_extras))
#foreach($categorie_extras as $categorie_extra)
<div class="col-4 form-group">{!! getExtraField($categorie_extra->extra_id, $advertisment->advertisment_number) !!}</div>
#endforeach
#endif
</div>
and my getExtraField Function in helper.php
//Helper für Anzeige der Extra Felder
function getExtraField($extra_id, $advertisment_number) {
$field = '';
$option = '';
// Extra aus DB holen
$extra = \Illuminate\Support\Facades\DB::table('extras')->where('id', '=', $extra_id)->first();
$advertisment_extras = \Illuminate\Support\Facades\DB::table('advertisment_extras')
->where('advertisment_number', '=', $advertisment_number)
->where('user_id', '=', \Illuminate\Support\Facades\Auth::user()->id)->get();
switch ($extra->extra_form_item) {
case 'input':
foreach($advertisment_extras as $advertisment_extra) {
if ($advertisment_extra->extra_id == $extra->id ) {
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><input type="' . $extra->extra_input_field_type . '" wire:model.lazy="extras.' . $extra->id . '" name="' . $extra->id . '" class="form-control" id="' . $extra->id . '">';
break;
} else {
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><input type="' . $extra->extra_input_field_type . '" wire:model.lazy="extras.' . $extra->id . '" name="' . $extra->id . '" class="form-control" id="' . $extra->id . '">';
}
}
break;
case 'select':
$values = explode(',', $extra->extra_enum_select_values);
// Option des Select Feldes suchen
$field_1 = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><select name="' . $extra->id . '" wire:model="extras.'. $extra->id . '" class="form-control" id="' . $extra->id . '">';
foreach ($values as $value) {
$option = $option .'<option value="'. $value . '">' . $value . '</option>';
}
$field_3 = '</select>';
$field = $field_1 . $option . $field_3;
break;
case 'checkbox' :
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><br><input type="checkbox" name="' . $extra->id . '" wire:model="extras.'. $extra->id . '" class="" value="1" id="' . $extra->id . '">';
break;
}
return $field;
}
and my complete component:
//Helper für Anzeige der Extra Felder
function getExtraField($extra_id, $advertisment_number) {
$field = '';
$option = '';
// Extra aus DB holen
$extra = \Illuminate\Support\Facades\DB::table('extras')->where('id', '=', $extra_id)->first();
$advertisment_extras = \Illuminate\Support\Facades\DB::table('advertisment_extras')
->where('advertisment_number', '=', $advertisment_number)
->where('user_id', '=', \Illuminate\Support\Facades\Auth::user()->id)->get();
switch ($extra->extra_form_item) {
case 'input':
foreach($advertisment_extras as $advertisment_extra) {
if ($advertisment_extra->extra_id == $extra->id ) {
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><input type="' . $extra->extra_input_field_type . '" wire:model.lazy="extras.' . $extra->id . '" name="' . $extra->id . '" class="form-control" id="' . $extra->id . '">';
break;
} else {
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><input type="' . $extra->extra_input_field_type . '" wire:model.lazy="extras.' . $extra->id . '" name="' . $extra->id . '" class="form-control" id="' . $extra->id . '">';
}
}
break;
case 'select':
$values = explode(',', $extra->extra_enum_select_values);
// Option des Select Feldes suchen
$field_1 = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><select name="' . $extra->id . '" wire:model="extras.'. $extra->id . '" class="form-control" id="' . $extra->id . '">';
foreach ($values as $value) {
$option = $option .'<option value="'. $value . '">' . $value . '</option>';
}
$field_3 = '</select>';
$field = $field_1 . $option . $field_3;
break;
case 'checkbox' :
$field = '<label for="' . $extra->id . '">' . $extra->extra_field_label . '</label><br><input type="checkbox" name="' . $extra->id . '" wire:model="extras.'. $extra->id . '" class="" value="1" id="' . $extra->id . '">';
break;
}
return $field;
}
my problem is that the value is not displayed in the fontend. That means the mount function does not work dynamically, but if I put it in directly as described above it works:
foreach ($xs as $x) {
$this->extras = [
'4' => '12345678'
];
}
but I would like to load the fields dynamically with values ​​like here:
foreach ($xs as $x) {
$this->extras = [
$x->extra_id => $x->extra_value,
];
}
Thanks for help :)

Related

Hide datatable row when total equals 0

->addColumn('name', function ($customer) {
$d = '';
if (request('due_filter')) {
$sum = $customer->invoices->whereIn('status', array('due', 'partial'));
$due = $sum->sum('total') - $sum->sum('pamnt');
$d = '<span class="badge badge-danger">' . amountFormat($due) . '</span>';
}
return '<a class="font-weight-bold" href="' . route('biller.customers.show', [$customer->id]) . '">' . $customer->name . '</a>' . $d;
})
How can I hide customer row if total equals 0.00?

Filling Data from MySQL not happening in Modal Form

My Modal is not firing on click of the button. I have tried every possible approach that I know and attempted all possible "Hit & Try" Methods. So I reverting to this forum for help. My Codes are follows:-
Main.php
<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial | Bootstrap Modal with Dynamic MySQL Data using Ajax & PHP</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<br /><br />
<div class="container" style="width:700px;">
<h3 align="center">Bootstrap Modal with Dynamic MySQL Data using Ajax & PHP</h3>
<br />
<div class="table-responsive">
<table id="recordsfromraky" class="table table-striped table-bordered">
</table>
</div>
</div>
</body>
</html>
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Employee Details</h4>
</div>
<div class="modal-body" id="employee_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
fetchChange();
$('.view_data').click(function(){
var employee_id = $(this).attr("id");
var fired_button = $(this).val();
alert(fired_button);
$('#dataModal').modal("show");
});
function fetchChange() {
var finyear = "2017-18";
var cmdname = "HQ TC";
var stnname = "All Stations";
var statusname = "All Status";
var cfaname = "All CFA";
var wkcatname = "All Categories";
$.ajax({
url:"get_value.php",
method:"POST",
data:{finyear:finyear, wkcatname:wkcatname,cmdname:cmdname,stnname:stnname, statusname:statusname,cfaname:cfaname},
success:function(data){
$('#recordsfromraky').html(data);
}
});
};
});
</script>
get_value.php code is as follows:-
<?php
ob_start();
include_once $_SERVER['DOCUMENT_ROOT'] . '/CommandWks/phpAssets/dbconnect.php';
ini_set("xdebug.var_display_max_children", -1);
ini_set("xdebug.var_display_max_data", -1);
ini_set("xdebug.var_display_max_depth", -1);
$finyr = $_POST['finyear'];
$commdname = $_POST['cmdname'];
$stationname = $_POST['stnname'];
$statustype = $_POST['statusname'];
$cfanamed = $_POST['cfaname'];
$catname = $_POST['wkcatname'];
$finyr = str_replace('"', '', $finyr);
$commdname = str_replace('"', '', $commdname);
$stationname = str_replace('"', "'", $stationname);
$statustype = str_replace('"', "", $statustype);
$cfanamed = str_replace('"', '', $cfanamed);
$catname = str_replace('"', '', $catname);
//var_dump($_POST);////////////////////////////////////////
$wherefy ='';
$wherecmd ='';
$wherestn = '';
$wherestatus ='';
$wherecfa ='';
$wherecat ='';
$tcn='';
if (empty($finyr)){
$wherefy = '';
}else{
$tcn = "'" . '%' . str_replace(' ', '', $finyr) . '%' . "'";
$wherefy = 'WHERE (`amwplist`.`Work_ID_by_MoD` LIKE ' . $tcn . ')';
}
if (!empty($stationname)) {
if ($stationname === "All Stations"){
$wherestn='';
}else{
$tcn='';
$tcn = "'" . str_replace("''", "", $stationname) . "'";
$wherestn = 'AND (`stationlist`.`Station` = ' . $tcn . ')';
}
}else{
$wherestn='';
}
if (!empty($commdname)) {
if ($commdname === "All Commands"){
$wherecmd='';
}else{
$tcn='';
$tcn = "'" . '%'. str_replace(' ', '', $commdname) . '%' . "'";
$wherecmd = 'AND (`amwplist`.`Work_ID_by_MoD` LIKE ' . $tcn . ')';
}
}else{
$wherecmd='';
}
if (!empty($statustype)) {
if ($statustype === "All Status"){
$wherestatus='';
}else{
$tcn='';
$tcn = "'" . '%'. $statustype . '%' . "'";
$wherestatus = 'AND (`workstatuslist`.`Status_Type` LIKE ' . $tcn . ')';
}
}else{
$wherestatus='';
}
if (!empty($cfanamed)) {
if ($cfanamed === "All CFA"){
$wherecfa='';
}else{
$tcn='';
$tcn = "'" . '%'. $cfanamed . '%' . "'";
$wherecfa = 'AND (`cfalist`.`CFA` LIKE ' . $tcn . ')';
}
}else{
$wherecfa='';
}
if (!empty($catname)) {
if ($catname === "All Categories"){
$wherecat='';
}else{
$tcn='';
$tcn = "'" . '%'. $catname . '%' . "'";
$wherecat = 'AND (`workscategorylist`.`Category_Type` LIKE ' . $tcn . ')';
}
}else{
$wherecat='';
}
$WhereCondition = $wherefy . " " . $wherestatus . " " . $wherestn . " " . $wherecfa . " " . $wherecat . " " . $wherecmd;
//var_dump( $WhereCondition);
//var_dump($wherefy);
//var_dump($wherecmd);
//var_dump($wherestn);
//var_dump($wherestatus);
//var_dump($wherecfa);
//ovar_dump($wherecat);
$sql ="SELECT
*
FROM `amwplist`
LEFT OUTER JOIN `workscategorylist` ON `amwplist`.`Category_ID` = `workscategorylist`.`Category_ID`
INNER JOIN `stationlist` ON `amwplist`.`Station_ID` = `stationlist`.`Station_ID`
LEFT OUTER JOIN `commandhqlist` ON `stationlist`.`Command_ID` = `commandhqlist`.`CommandHQ_ID`
LEFT OUTER JOIN `sectorlist` ON `stationlist`.`Sector_ID` = `sectorlist`.`Sector_ID`
LEFT OUTER JOIN `celist` ON `stationlist`.`CE_ID` = `celist`.`CE_ID`
LEFT OUTER JOIN `cwelist` ON `stationlist`.`CWE_ID` = `cwelist`.`CWE_ID`
LEFT OUTER JOIN `gelist` ON `stationlist`.`GE_ID` = `gelist`.`GE_ID`
LEFT OUTER JOIN `ifalist` ON `amwplist`.`IFA_ID` = `ifalist`.`IFA_ID`
LEFT OUTER JOIN `cdalist` ON `stationlist`.`CDA_ID` = `cdalist`.`CDA_ID`
LEFT OUTER JOIN `cfalist` ON `amwplist`.`CFA_ID` = `cfalist`.`CFA_ID`
LEFT OUTER JOIN `workstatuslist` ON `amwplist`.`Status_ID` = `workstatuslist`.`Status_ID` " .
$WhereCondition . " " .
"ORDER BY substring_index(amwplist.Work_ID_by_MoD, '/', 1), CONVERT(substring_index(amwplist.Work_ID_by_MoD, '/', -1), UNSIGNED INTEGER)
";
$tableRow = '<thead>
<tr>
<th>Category Type</th>
<th>Station</th>
<th>MoD ID</th>
<th>Nomenclature</th>
<th>Cost</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
$conn = new mysqli($DBSERVER, $DBUSER, $DBPASS, $DBNAME);
$result = mysqli_query($conn, $sql);
//var_dump($conn);
while ($row= mysqli_fetch_array($result)) {
//$idnumber = CONVERT(substring_index($row['Work_ID_by_MoD'], '/', -1), UNSIGNED INTEGER);
$tableRow = $tableRow . '<tr>' ;
$tableRow = $tableRow . '<td>'. $row['Category_Type'] . '</td>';
$tableRow = $tableRow . '<td>'. $row['Station'] . '</td>';
$trow = $row['Work_ID_by_MoD'];
//var_dump($trow);
//var_dump('<td><input type="button" name= "' . $row['Work_ID_by_MoD'] . '" value= "' . $row['Work_ID_by_MoD'] . '" id= "' . $row['Work_ID_by_MoD'] . '" class="btn btn-info btn-xs view_data" /></td>');
$tableRow = $tableRow . '<td><input type="button" name= "' . $trow . '"' . 'value= "' . $trow . '" id= "' . $trow . '" class="btn btn-info btn-xs view_data" /></td>';
$tableRow = $tableRow . '<td>'. $row['Nomenclature'] . '</td>';
$tableRow = $tableRow . '<td>'. $row['Cost'] . '</td>';
$tableRow = $tableRow . '<td>'. $row['Status_Type'] . '</td>';
$tableRow = $tableRow . '</tr>';
}
$tableRow = $tableRow . '</tbody>';
//var_dump($tableRow);
echo ($tableRow);
$conn->close();
ob_end_flush();
?>
The function .click() on clicking the MoD ID in the third column is not firing. The content of rows in this column looks like this:-
<input type="button" name="AMWP/2017-18/1" value="AMWP/2017-18/1" id="AMWP/2017-18/1" class="btn btn-info btn-xs view_data">
<input type="button" name="AMWP/2017-18/2" value="AMWP/2017-18/2" id="AMWP/2017-18/2" class="btn btn-info btn-xs view_data">
<input type="button" name="AMWP/2017-18/3" value="AMWP/2017-18/3" id="AMWP/2017-18/3" class="btn btn-info btn-xs view_data">
I now think that maybe there are Handle issues here because the table is being filled by get_value.php into main.php and then I am trying to fire Modal by clicking the button generated by get_value.php.
The problem is that you try to bind a click event on a non existing object. i.e. $('.view_data').click(... happens before your ajax call is finished and therefore there are no elements that have the class view_data.
You have two options:
1) don't bind the event on the button, but on body. I personally prefer this method because it doesn't bind the event but uses a delegation. It's easier to debug and maintain (especially if you end up having a lot of events in one document):
$('body').on('click', '.view_data', function(){
alert('clicked ' + $(this).val());
});
2) put the event binding in the success method of the ajax call AFTER you write the results to the DOM
fetchChange();
function fetchChange() {
var finyear = "2017-18";
var cmdname = "HQ TC";
var stnname = "All Stations";
var statusname = "All Status";
var cfaname = "All CFA";
var wkcatname = "All Categories";
$.ajax({
url:"get_value.php",
method:"POST",
data:{finyear:finyear, wkcatname:wkcatname,cmdname:cmdname,stnname:stnname, statusname:statusname,cfaname:cfaname},
success:function(data){
$('#recordsfromraky').html(data);
$('.view_data').click(function(){
var employee_id = $(this).attr("id");
var fired_button = $(this).val();
alert(fired_button);
$('#dataModal').modal("show");
});
}
});
};
});
The amended get_value.php is as follows:-
<?php
ob_start();
include_once $_SERVER['DOCUMENT_ROOT'] . '/CommandWks/phpAssets/dbconnect.php';
ini_set("xdebug.var_display_max_children", -1);
ini_set("xdebug.var_display_max_data", -1);
ini_set("xdebug.var_display_max_depth", -1);
$finyr = $_POST['finyear'];
$commdname = $_POST['cmdname'];
$stationname = $_POST['stnname'];
$statustype = $_POST['statusname'];
$cfanamed = $_POST['cfaname'];
$catname = $_POST['wkcatname'];
$finyr = str_replace('"', '', $finyr);
$commdname = str_replace('"', '', $commdname);
$stationname = str_replace('"', "'", $stationname);
$statustype = str_replace('"', "", $statustype);
$cfanamed = str_replace('"', '', $cfanamed);
$catname = str_replace('"', '', $catname);
//var_dump($_POST);////////////////////////////////////////
$wherefy ='';
$wherecmd ='';
$wherestn = '';
$wherestatus ='';
$wherecfa ='';
$wherecat ='';
$tcn='';
if (empty($finyr)){
$wherefy = '';
}else{
$tcn = "'" . '%' . str_replace(' ', '', $finyr) . '%' . "'";
$wherefy = 'WHERE (`amwplist`.`Work_ID_by_MoD` LIKE ' . $tcn . ')';
}
if (!empty($stationname)) {
if ($stationname === "All Stations"){
$wherestn='';
}else{
$tcn='';
$tcn = "'" . str_replace("''", "", $stationname) . "'";
$wherestn = 'AND (`stationlist`.`Station` = ' . $tcn . ')';
}
}else{
$wherestn='';
}
if (!empty($commdname)) {
if ($commdname === "All Commands"){
$wherecmd='';
}else{
$tcn='';
$tcn = "'" . '%'. str_replace(' ', '', $commdname) . '%' . "'";
$wherecmd = 'AND (`amwplist`.`Work_ID_by_MoD` LIKE ' . $tcn . ')';
}
}else{
$wherecmd='';
}
if (!empty($statustype)) {
if ($statustype === "All Status"){
$wherestatus='';
}else{
$tcn='';
$tcn = "'" . '%'. $statustype . '%' . "'";
$wherestatus = 'AND (`workstatuslist`.`Status_Type` LIKE ' . $tcn . ')';
}
}else{
$wherestatus='';
}
if (!empty($cfanamed)) {
if ($cfanamed === "All CFA"){
$wherecfa='';
}else{
$tcn='';
$tcn = "'" . '%'. $cfanamed . '%' . "'";
$wherecfa = 'AND (`cfalist`.`CFA` LIKE ' . $tcn . ')';
}
}else{
$wherecfa='';
}
if (!empty($catname)) {
if ($catname === "All Categories"){
$wherecat='';
}else{
$tcn='';
$tcn = "'" . '%'. $catname . '%' . "'";
$wherecat = 'AND (`workscategorylist`.`Category_Type` LIKE ' . $tcn . ')';
}
}else{
$wherecat='';
}
$WhereCondition = $wherefy . " " . $wherestatus . " " . $wherestn . " " . $wherecfa . " " . $wherecat . " " . $wherecmd;
//var_dump( $WhereCondition);
//var_dump($wherefy);
//var_dump($wherecmd);
//var_dump($wherestn);
//var_dump($wherestatus);
//var_dump($wherecfa);
//ovar_dump($wherecat);
$sql ="SELECT
*
FROM `amwplist`
LEFT OUTER JOIN `workscategorylist` ON `amwplist`.`Category_ID` = `workscategorylist`.`Category_ID`
INNER JOIN `stationlist` ON `amwplist`.`Station_ID` = `stationlist`.`Station_ID`
LEFT OUTER JOIN `commandhqlist` ON `stationlist`.`Command_ID` = `commandhqlist`.`CommandHQ_ID`
LEFT OUTER JOIN `sectorlist` ON `stationlist`.`Sector_ID` = `sectorlist`.`Sector_ID`
LEFT OUTER JOIN `celist` ON `stationlist`.`CE_ID` = `celist`.`CE_ID`
LEFT OUTER JOIN `cwelist` ON `stationlist`.`CWE_ID` = `cwelist`.`CWE_ID`
LEFT OUTER JOIN `gelist` ON `stationlist`.`GE_ID` = `gelist`.`GE_ID`
LEFT OUTER JOIN `ifalist` ON `amwplist`.`IFA_ID` = `ifalist`.`IFA_ID`
LEFT OUTER JOIN `cdalist` ON `stationlist`.`CDA_ID` = `cdalist`.`CDA_ID`
LEFT OUTER JOIN `cfalist` ON `amwplist`.`CFA_ID` = `cfalist`.`CFA_ID`
LEFT OUTER JOIN `workstatuslist` ON `amwplist`.`Status_ID` = `workstatuslist`.`Status_ID` " .
$WhereCondition . " " .
"ORDER BY substring_index(amwplist.Work_ID_by_MoD, '/', 1), CONVERT(substring_index(amwplist.Work_ID_by_MoD, '/', -1), UNSIGNED INTEGER)
";
$tableRow = '<thead>
<tr>
<th>Category Type</th>
<th>Station</th>
<th>MoD ID</th>
<th>Nomenclature</th>
<th>Cost</th>
<th>Status</th>
</tr>
</thead>
<tbody>';
$conn = new mysqli($DBSERVER, $DBUSER, $DBPASS, $DBNAME);
$result = mysqli_query($conn, $sql);
//var_dump($conn);
while ($row= mysqli_fetch_array($result)) {
//$idnumber = CONVERT(substring_index($row['Work_ID_by_MoD'], '/', -1), UNSIGNED INTEGER);
$tableRow = $tableRow . '<tr>' ;
$tableRow = $tableRow . '<td>'. $row['Category_Type'] . '</td>';
$tableRow = $tableRow . '<td>'. $row['Station'] . '</td>';
$trow = $row['Work_ID_by_MoD'];
//var_dump($trow);
//var_dump('<td><input type="button" name= "' . $row['Work_ID_by_MoD'] . '" value= "' . $row['Work_ID_by_MoD'] . '" id= "' . $row['Work_ID_by_MoD'] . '" class="btn btn-info btn-xs view_data" /></td>');
$tableRow = $tableRow . '<td><input type="button" name= "' . $trow . '"' . 'value= "' . $trow . '" id= "' . $trow . '" class="btn btn-info btn-xs view_data" /></td>';
$tableRow = $tableRow . '<td>'. $row['Nomenclature'] . '</td>';
$tableRow = $tableRow . '<td>'. $row['Cost'] . '</td>';
$tableRow = $tableRow . '<td>'. $row['Status_Type'] . '</td>';
$tableRow = $tableRow . '</tr>';
}
$tableRow = $tableRow . '</tbody>';
$tableRow = $tableRow . "<script>$('.view_data'" . ").click(function(){
var employee_id = $(this).attr('id');
var fired_button = $(this).val();
alert(fired_button);
$('#dataModal').modal('show');
});
</script>";
//var_dump($tableRow);
echo ($tableRow);
$conn->close();
ob_end_flush();
?>
Please not the appending of at the end of the loop. That too did the trick.

how to get onchange value after select navigation menu in magento?

hi all how to get onchange value after select navigation menu in magento?
i trying to following code in topmenu.phtmlbut it's not working proper showing page is not found
But it's not working properly. What do i do?
you can try something like this
<select id="nav" class="nav" onchange="if (this.value) window.location.href=this.value">
Update Topmenu.php code with below code.
Remove this:
$html .= '<option ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml($child->getName()) . '</span></a>';
if ($child->hasChildren()) {
if (!empty($childrenWrapClass)) {
$html .= '<div class="' . $childrenWrapClass . '">';
}
$html .= '<ul class="level' . $childLevel . '">';
$html .= $this->_getHtml($child, $childrenWrapClass);
$html .= '</ul>';
if (!empty($childrenWrapClass)) {
$html .= '</div>';
}
}
$html .= '</option>';
Add below code:
$html .= '<option value="' . $child->getUrl() . '" '>'. $this->escapeHtml($child->getName()) . '</option>';
if ($child->hasChildren()) {
$html .= $this->_getHtml($child, $childrenWrapClass);
}
And update select onchange code with below code:
onchange="if (this.value) window.location.href=this.value"

magento how to make a parent menu link which has subcategories not clickable

Can someone help me with this please? I'm using Magento CE 1.8.0.0
magento how to make a parent menu link which has subcategories not clickable
I've tried the below codes, they don't work for me either.
app/code/core/Mage/Catalog/Block or Topmenu.php
if($category->getLevel()== 2 && $hasActiveChildren) {
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.' onclick="return false;">';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
} else {
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
}
if ($category->getID()==[category ID]) {
$linkClass = 'class="no-click"';
$html[] = '<a href="javascript:void(0)"'.$linkClass.'>';
}
else{
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>;';
}
To make it works on top level only:
app/code/local/Mage/Page/Block/Html/Topmenu.php, line 126 replace this code
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . '</span></a>';
With :
if ($child->hasChildren() && $childLevel == 0 ) {
$html.= '<a href="#" ' . $outermostClassCode . ' onclick="return false;"><span>'
. $this->escapeHtml($child->getName()) . '</span></a>'."\n";
}
else {
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . '</span></a>';
}
Titonja has the answer here:
app/code/local/Mage/Page/Block/Html/Topmenu.php
Around line 126. Find this code:
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . '</span></a>';
Replace with:
if ($child->hasChildren()) {
$html.= '<a href="#" ' . $outermostClassCode . ' onclick="return false;"><span>'
. $this->escapeHtml($child->getName()) . '</span></a>'."\n";
}
else {
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
. $this->escapeHtml($child->getName()) . '</span></a>';
}
Clear cache. It works for me on Magento 1.8.0.0
For people with version 1.6.2, try this:
Look for the file: /app/code/core/Mage/Catalog/Block/Navigation.php
Replace line 268:
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
By this conditional:
$myParentIds = array(3,6,10);
if (in_array($category->getID(), $myParentIds)){
$linkClass = ' class="no-click"';
$html[] = '<a href="javascript:void(0)"'.$linkClass.'>';
}
else{
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
}
I hope this helps.
app/code/local/Mage/Page/Block/Html/Topmenu.php
Around line 126. Find this code:
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'. $this->escapeHtml($child->getName()) . '</span></a>';
Replace with:
if ($child->hasChildren() && $childLevel == 0) {
$html.= '<span>'. $this->escapeHtml($child->getName()) . '</span>'."\n";
} else {
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'. $this->escapeHtml($child->getName()) . '</span></a>';
}

DOB select boxes on Magento registration form

I'm currently using Magento 1.5.0.1
When a customer reigisters on the registration page (/account/create), he has to insert a date of birth (dob).
By default, the date of birth consists of 3 text-boxes. I have modified the file at /app/design/frontend/base/default/template/customer/widget.
So, instead of text-boxes there are now 3 select-boxes where the user can select a date
However, when all information is filled in correctly and you click on the "submit" button nothing happens (no errors, messages or anything).
Any idea on how to make the "submit" button work again?
Thanks
Edit:
The id's of the are the same as the one's used by the "". I've posted the code that I have changed
I've made 2 functions that print the options's element:
function getOptions($minValue, $maxValue)
{
$options = "";
for ($count = $minValue; $count <= $maxValue; $count++)
{
$options = $options . '<option value="' . $count . '">' . $count . '</option>';
}
return $options;
}
function getYears()
{
$years = "";
$currentYear = date('Y');
for ($count = 1900; $count <= $currentYear; $count++)
{
$years = $years . '<option value="' . $count;
if ($count == '1980')
{
$years = $years . '" selected="selected"';
}
$years = $years . '">' . $count . '</option>';
}
return $years;
}
And i've changed the input type=text to select
$this->setDateInput('d',
'<div class="dob-day">
<label for="' . $this->getFieldId('day') . '">' . $this->__('DD') . '</label>
<select id="' . $this->getFieldId('day') . '" name="' . $this->getFieldName('day') . '" title="' . $this->__('Day') . '" class="validate-select" ' . $this->getFieldParams() . '>' . getOptions(1,31) . '
</select>
</div>
<br />');
$this->setDateInput('m',
'<div class="dob-month">
<label for="' . $this->getFieldId('month') . '">' . $this->__('MM') . '</label>
<select id="' . $this->getFieldId('month') . '" name="' . $this->getFieldName('month') . '" title="' . $this->__('Month') . '" class="validate-select"' . $this->getFieldParams() . '>' . getOptions(1,12) . '
</select>
</div>
<br />');
$this->setDateInput('y',
'<div class="dob-year">
<label for="' . $this->getFieldId('year') . '">' . $this->__('YYYY') . '</label>
<select id="' . $this->getFieldId('year') . '" name="' . $this->getFieldName('year') . '" title="' . $this->__('Year') . '" class="validate-select"' . $this->getFieldParams() . '>' . getYears() . '
</div>'
);
Replace/create dob.phtml file located in app/design/frontend/[package-name]/default/template/customer/widget/
https://gist.github.com/ncla/7794502 (tested on Magento 1.8 community edition)
Accepted answer might work, but hiding inputs seems unacceptable. Also setDateInput, getSortedDateInputs methods are unnecessary, as you pass them HTML just to get them back.
If you try converting dob.phtml from input boxes to drop down boxes, Magento form validation will fail (throw JS error) because it can't find "day" input. So I just override Varien.DOB initialize function to select correct elements.
Plz replace the dob.phtml in
app/design/frontend/base/default/template/customer/widget/
to follwing code and override new field to old with the help of css
/////////////////////////////
<?php echo $this->getLayout()->createBlock('customer/widget_dob')
->setDate($this->getCustomer()->getDob())
->toHtml() ?>
// For checkout/onepage/billing.phtml:
<?php echo $this->getLayout()->createBlock('customer/widget_dob')
->setDate($this->getCustomer()->getDob())
->setFieldIdFormat('billing:%s')
->setFieldNameFormat('billing[%s]')
->toHtml() ?>
/* NOTE: Regarding styles - if we leave it this way, we'll move it to boxes.css
Alternatively we could calculate widths automatically using block input parameters.
*/
/**
* #see Mage_Customer_Block_Widget_Dob
*/
<label for="<?php echo $this->getFieldId('month')?>"<?php if ($this->isRequired()) echo ' class="required"' ?>><?php if ($this->isRequired()) echo '<em>*</em>' ?><?php echo $this->__('Date of Birth') ?></label>
<div class="input-box customer-dob">
<?php
$this->setDateInput('d',
'<div class="dob-day">
<input type="text" id="' . $this->getFieldId('day') . '" name="' . $this->getFieldName('day') . '" value="' . $this->getDay() . '" title="' . $this->__('Day') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
<label for="' . $this->getFieldId('day') . '">' . $this->__('DD') . '</label>
</div>'
);?>
<select name="nday" id="nday" onchange="getElementById('<?php echo $this->getFieldId('day');?>').value=this.value" style="width:90px;">
<option value="">Select</option>
<?php
for($i=1;$i<=31;$i++)
{
echo "<option value='".$i."'>".$i."</option>";
}
?>
</select>
<select name="nmon" id="nmon" onchange="getElementById('<?php echo $this->getFieldId('month');?>').value=this.value" style="width:90px;">
<option value=''>Select</option>
<?php echo '<option value="">'.$this->__("Select").'</option>'.'<option value="01">'.$this->__("January").'</option>'.'<option value="02">'.$this->__("February").'</option>'.'<option value="03">'.$this->__("March").'</option>'.'<option value="04">'.$this->__("April").'</option>'.'<option value="05">'.$this->__("May").'</option>'.'<option value="06">'.$this->__("June").'</option>'.'<option value="07">'.$this->__("July").'</option>'.'<option value="08">'.$this->__("August").'</option>'.'<option value="09">'.$this->__("September").'</option>'.'<option value="10">'.$this->__("October").'</option>'.'<option value="11">'.$this->__("November").'</option>'.'<option value="12">'.$this->__("December").'</option>'; ?>
</select>
<select name="nyear" id="nyear" onchange="getElementById('<?php echo $this->getFieldId('year');?>').value=this.value" style="width:90px;">
<option value="">Select</option>
<?php
for($j=date('Y')-80;$j<=date('Y');$j++)
{
echo "<option value='".$j."'>".$j."</option>";
}
?>
</select>
</p>
<?php
$this->setDateInput('m',
'<div class="dob-month">
<input type="text" id="' . $this->getFieldId('month') . '" name="' . $this->getFieldName('month') . '" value="' . $this->getMonth() . '" title="' . $this->__('Month') . '" class="input-text validate-custom" ' . $this->getFieldParams() . '/>
<label for="' . $this->getFieldId('month') . '">' . $this->__('MM') . '</label>
</div>'
);
$this->setDateInput('y',
'<div class="dob-year">
<input type="text" id="' . $this->getFieldId('year') . '" name="' . $this->getFieldName('year') . '" value="' . $this->getYear() . '" title="' . $this->__('Year') . '" class="input-text validate-custom" ' . $this->getFieldParams() . ' />
<label for="' . $this->getFieldId('year') . '">' . $this->__('YYYY') . '</label>
</div>'
);
?>
<?php echo $this->getSortedDateInputs() ?>
<div class="dob-full" style="display:none;">
<input type="hidden" id="<?php echo $this->getFieldId('dob')?>" name="<?php echo $this->getFieldName('dob')?>" />
</div>
<div class="validation-advice" style="display:none;"></div>
</div>
<script type="text/javascript">
//<![CDATA[
var customer_dob = new Varien.DOB('.customer-dob', <?php echo $this->isRequired() ? 'true' : 'false' ?>, '<?php echo $this->getDateFormat() ?>');
//]]>
</script>
////////////////////////////
it work fine .this is just an idea.......
enjoy
Thats how I did it. Maybe someone can use it
Grab the dob code from some site or from Magento default theme
Create your own widget template in your theme folder, for example customer/widget/dob-custom.phtml
Call this widget in your template file, for example
echo $this->getLayout()->createBlock('customer/widget_dob')->setTemplate('customer/widget/dob-custom.phtml')->toHtml();
The issue I think is because the format of the DD is not correct. You are generating a day like 1, 2, 3, 4... while it should be 01, 02, 03, 04,.. etc..
Regards!
I recently switched from ncla's solution to this:
http://www.endreywalder.com/blog/change-date-of-birth-field-to-select-boxes-in-magento/
Instead of displaying 01-12 for months, this will output the actual names which I like much better.
Tested on Magento 1.9.2

Resources