TimePicker - Set the minTime greater than the selected start-time - timepicker

I have a star-time and end-time option which is working well.
start-time [8:00am, 8:30am, 9:00am, 9:30am, 10:00am]
end-time [8:00am, 8:30am, 9:00am, 9:30am, 10:00am]
If the user start-time selection is 9:00am, I have the following code working
$('#start-time').change(function(){
$('#end-time').timepicker('option','minTime',$(this).val());
});
However, the above code shows options as
end-time [9:00am, 9:30am, 10:00am]
If the user start-time selection is 9:00am, then I would like the end-time options to only have greater tiles
end-time [9:30am, 10:00am] (only)
How can I set the end-time greater than the selected start-time?

Time-picker builds a LI list of options and adds a class ui-timepicker-selected.
I was able to grab the entire list then find the LI.ui-timepicker-selected class.
Once I grab the start-time value, I use jquery to go to the next item in the List and use the next value as my minTime.
Here is the code that is working:
$('#start-time').change(function(){
var nexttime = $('li.ui-timepicker-selected').next('li').text();
$('#end-time').timepicker('option','minTime',nexttime);
});

Related

logic in setFormat to not roundup the values

I created a range using offset and setting the format for the range
I did that using below code
a1_range = Sheet1.getRange("D43");
var a4_range = a1_range.offset(0,6);
a4_range = a4_range.offset(0,1,15,6);
a4_range.setBackground("#e6e6e6").setBorder(true, true, true, true, true, true);
a4_range.setNumberFormat("$#");
The setNumberFormat is setting is write as I want , but the problem is when user enters the data, it is rounding up the value as shown in the picture.
However, to not round the values, I did this
a4_range.setNumberFormat("$#, ##0.000000");
This works but has extra trailing zeroes which I do not want as below,
What I want is when user comes and enters 56.768 in that range, the value should be exactly $56.768 and NOT 56.768000 and NOT have it round off to any decimal places.
Similarly, if the user enters 34.3 then it should be $34.3 and if user enters 8.98945 it should be $8.98945
How do I achieve this?
Try this:
a4_range.setNumberFormat("$0.#######");

Sorting on empty kendo grid shows old data

I have a dropdown(having 2 values - Employee and department) and two kendogrids(emp grid and dept grid), on change of dropdown I am enabling/disabling grid based on dropdown value and also clearing datasource of both grid, when I select employee in dropdown and sort employees based on name it gives results, when i change dropdown value to 'Department' it disables employee grid and shows 'No data found' in employee grid,but when I clicked on EmpName column i still got the previous results. I have added dropdown change sample code below.
var ddlvalue = $("#drpmodule").data("kendoDropDownList").text();
$("#EmpGrid").data("kendoGrid").dataSource.data([]); //Clear EmpGrid DataSource
$("#DeptGrid").data("kendoGrid").dataSource.data([]); //Clear DeptGrid DataSource
if (module == 'Employee') {
$('#DeptGrid').addClass('k-state-disabled');
$('#EmpGrid').removeClass('k-state-disabled');
}
else if (module == 'Department') {
$('#EmpGrid').addClass('k-state-disabled'); //shows no data found in EmpGrid, but clicking on column header gives results
$('#DeptGrid').removeClass('k-state-disabled');
} else {
$('#EmpGrid').removeClass('k-state-disabled');
$('#DeptGrid').removeClass('k-state-disabled');
}
I am not getting why Employee grid is showing previous/old data even after 'No data found' records(on changing dropdown).
It would be nice to see how the datasource is configured.
As it is I can assume that maybe when you are filtering, the datasource is fetching data. It would explain why you see data on filtering the empty grid.
Maybe hiding the disabled grid could be a solution : $('#EmpGrid').hide();
Then display it again $('#EmpGrid').show();
By hiding/showing the grid you don't need to empty the grid anymore.

Angular 2 - Disable form control based on the value of another form control

I need help in disabling the value of a specific form control based on its value in Angular 2.
The field - startDate needs to be disabled whenever the value of another field - period is "Lifetime". It needs to be enabled otherwise. Also, whenever the app is loaded, the default value of period is "Lifetime" so the startDate is disabled when the form is loaded.
So this is the code that I have written till now in my component:
protected onMetadataLoaded() {
const startDateControl = this.metadata.form.controls.startDate;
startDateControl.disable();
const periodControl = this.metadata.form.controls.period;
periodControl.valueChanges
.distinctUntilChanged()
.subscribe(period => {
if(period !== "Lifetime") {
startDateControl.enable();
} else {
startDateControl.disable();
}
});
}
This allows me to enable the startDateControl when I change the period value from Lifetime to any other value. However, if I select the period value as Lifetime again, the startDateControl doesn't get disabled.
I'm guessing that it's checking it only once since I'm putting the code inside MetadataLoaded(). I'm not sure as to how I need to go about it so that it keeps monitoring the periodControl for value changes and enables and disables the startDateControl based on the period value.
Just for completeness: Period field has the following values - Monthly, Quarterly, Yearly, Lifetime.
Thanks in advance!
EDIT:
So this is what my template looks like:
<dynamic-form-item name="storeID" [metadata] = "metadata" type="chooser"></dynamic-form-item>
<dynamic-form-item name="period" [metadata] = "metadata"></dynamic-form-item>
<dynamic-form-item name="startDate" [metadata] = "metadata"></dynamic-form-item>
Basically a bunch of dynamic form items.

Opencart + unique product with options + stock control

I make bracelets and place them in my opencart store. Each bracelet is unique, so I have 1 in stock. But customer has to let me know the size of his/her wrist so I can adapt it.
Options ask me for quantities. So, I can not use them because I must enter a number or the option does not become visible.
What I need is:
bracelet B ---> tell me your wrist´s size: (here a drop down or a text box to let the customer choose or write).
Order will reads: Bracelet B... Size: 18cm.... xx $
Then, when the customer pays, Bracelt B is out of stock.
Now, I can do all that, but any time a customer adds an option, the bracelet keeps available.
So Order reads:
Bracelet B ... Size: 18cm... xx$
Bracelet B ... Size: 19cm... xx$ etc
function addToCart(product_id, quantity) {
quantity = typeof(quantity) != 'undefined' ? quantity : 1;
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + quantity,
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, .information, .error').remove();
if (json['redirect']) {
location = json['redirect'];
}
if (json['success']) {
$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.success').fadeIn('slow');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
/*adding Shadyyx solution*/
if (json['error']) {
$('#notification').html('<div class="error" style="display: none;">' + json['error'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('.error').fadeIn('slow');
}
/*end adding*/
}
});
}
In default OC You have the ability to disable ordering of out of stock products.
Simply go to the administration -> System -> Settings, click edit on Your store and navigate to the Options tab. Then scroll down to the Stock section and notice the Stock Checkout: option. If You select No and save the users won't be able to order the products that are not in stock.
This means that if You create a bracelet product with 1 piece in stock, add an option to it with one piece in stock and somebody order this one, it's stock will be immediately set to Not in stock and nobody will be able to order it again.
If You'd like to hide all the products that are not in stock after they are ordered, You have two options - either do this manually by disabling the product or You'd need to implement few modifications in to the getProducts() method for the product model to load only those products that are still in stock.
UPDATE regarding the comment: You are misunderstaning the options in OpenCart. One option for which You have the stock 1 piece is the size option, which may have different values, e.g. 15cm, 16cm, 17cm, 18cm, etc. All these values contained in one single size option for one single stock item mean that if I select any of them, after ordering the bracelet there will no more pieces left.
What You are telling is creating one option for 15cm with 1pcs stock, another option for 16cm with 1pcs stock, etc., thus having 1 piece in stock for each size - this is incorrect (i.e. misuse of product options). Nevertheless, even in this case, when different sizes have all one piece but the product itself has only one piece, after ordering first it should be out of the stock even there are options with stock left...
Step by step walkthrough:
Go to Your OC administration and log in.
Hover the mouse over the Catalog menu point and click on the Options entry
On this Options overview screen notice the Insert in the top-right corner - click it
Enter the Option's name, e.g. Wrist Size
Choose the Option's type, either Select or Radio (depending on how many possible values You want to have, more than 4, use Select)
Sort Order may be a numeric value (or when blank, will be filled with 0)
Now there is empty table underneath with one row containing only a button Add Option Value - by clicking this it will add a row with empty form fields to enter the Option's value; let's say we want to add wrist sizes from 15cm to 22cm => 8 values => click that button 8 times (be careful, after each click it will be moved downward as a new row with form fields will appear above it)
into that 8 rows enter all the necessary values, e.g. 15cm, 16cm, ..., 22cm as value's name and sort order to match Your needs (leaving blank may lead to inappropriately ordered values when displayed)
Click on Save button located at top-right corner.
Now navigate Yourself to the products overview, select the product You want to add this option to and click Edit in that row. Move to the Data tab and make sure the bracelet has these settings:
Quantity: 1
Subtract Stock: Yes
Out of Stock Status: Out of Stock
Then move to the Option tab and add the new option by typing the Option's name (Wrist Size) in the left area - after the Option is found, click on that label and a new Option (new tab) will be added to the view. Now make sure the Option is required and add all possible values while setting these settings to all of them:
Quantity: 1
Subtract Stock: Yes
The other option values depends on Your business model. Now Save the product and try to order it with any of the wrist sizes value. If You have the settings set for the store that the customer isn't possible to order the products that are out of stock, this should work for You.
Let me know if there is something that I missed (or if it still doesn't work).
UPDATE:
Here is one possible solution (not tested but I believe it will work out of the box or maybe there is only simple bug You may fix Yourself):
Open up the catalog/controller/checkout/cart.php and find this line (should be at 543):
$this->cart->add($this->request->post['product_id'], $quantity, $option);
and before this line directly add this code (You may want to do this via vQmod extension):
if ($product_info['quantity'] == 1 && $product_info['subtract'] == 1) {
$products = $this->cart->getProducts();
$already_added = false;
foreach ($products as $product) {
if ($product['product_id'] == $this->request->post['product_id']) {
$already_added = true;
break;
}
}
if ($already_added) {
return $this->response->setOutput(json_encode(array(
'error' => $this->language->get('text_product_already_added')
)));
}
}
Then open up this file catalog/language/english/checkout/cart.php and add this to the end:
$_['text_product_already_added'] = 'This product has allowed quantity of 1 piece and is already added to a cart. Remove it from the cart to be able to add it (e.g. with different size).';
This is all only as an example, You may edit the error message to meet Your requirements.
Warning: this is only a simple solution not letting the same user (or within the same session) to add the same product twice or more times into the cart but it won't prevent the same product being added and ordered at the very same time by two different users (or one user using two browsers, for example). For this edge case You'd need to implement some kind of product locking - after it is added to cart this is saved to a DB and nobody else would be able to add the same product into the cart. In this case it would be nice to store also the datetime when it was locked and have a cron job that will unlock this product (also with removing from the cart) so that the product is not locked for ever and is orderable by other users again...
EDIT for JS part:
Open up this file catalog/view/javascript/common.js and search for method function addToCart(product_id, quantity) { - in this file find this part:
if (json['success']) {
...
}
and after this one add this code:
if (json['error']) {
$('#notification').html('<div class="error" style="display: none;">' + json['error'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('.error').fadeIn('slow');
}
This should be enough.
UPDATE XYZ:
In PHP find this code what have we added:
return $this->response->setOutput(json_encode(array(
'error' => $this->language->get('text_product_already_added')
)));
and change it to this (then try):
$this->response->setOutput(json_encode(array(
'error' => $this->language->get('text_product_already_added')
)));
return;
The point is to see in console where the request is done to index.php?route=checkout/cart/add the response with either success or error message in response. Try for both cases to make sure You are looking at the correct request (in success You can see the success message on the top of page so You may be sure it was done) and then try again to receive error (for the same product) message - it should be contained in the response the same way as the success message is. If still doesn't work, try to change return; to exit;...
Unfortunately I can't comment your post.
I had the problem with error message not showing up, when trying to add the product twice.
I needed to add the JS code to /catalog/view/theme/*/product/product.tpl
Just search for "url: 'index.php?route=checkout/cart/add'" and add the code shadyxx postet right after
if (json['success']) { ... }

List Box enable/disable one column

Access 2007: Is it possible to enable/disable one column in a List Box on a form. For example: Say you have 2 columns A,B - If Me.A = title Then Me.B.Enabled = True Else Me.B.Enabled = False.
If so, where would it go? On Got Focus, On Click??
Thanks
I'm not sure what you mean by disable, but you can hide a column by adjusting the ColumnWidth.
So if you wanted to hide column2:
Me.MyListBox.ColumnWidths = (1 in;0;1 in)
And to hide column1:
Me.MyListBox.ColumnWidths = (0;1 in;1 in)