Open chullski opened 11 years ago
Do it this way:
var minWidth = 150;
var minHeight = 100;
gridster = $('.gridster ul').gridster({
widget_base_dimensions: [minWidth, minHeight],
widget_margins: [5, 5],
helper: 'clone',
resize: {
enabled: true,
max_size: [5, 5],
resize: function (event, ui, $widget) {
if ($widget.width() <= minWidth) {
$widget.width(minWidth);
}
if ($widget.height() <= minHeight) {
$widget.height(minHeight);
}
}
}
}).data('gridster');
It doesn't work because during your mouse is resizing it's okay, but if you even go smaller that it is authorized and you release the click it resize.
To reproduce that I have set minWith and minHeight to 200 and widget_base_dimensions to 100
I'm not sure I understand, look at this example, it's working fine: http://jsfiddle.net/RzLf5/6/
If you want to prevent the resizing when you release your mouse button in a zone that is smaller than your authorized size, you can always put a check like this:
resize: {
start: function (event, ui, $widget) {
original_width = $widget.width();
original_height = $widget.height();
}
stop: function (event, ui, $widget) {
if ($widget.width() <= minWidth) {
$widget.width(original_width);
}
if ($widget.height() <= minHeight) {
$widget.height(original_height);
}
}
}
How would you limit the widgets min-width to be the width of input items inside of a widget. I forked your jsfiddle here: http://jsfiddle.net/isaacbarnes/tSdRb/. If you click add widget you can see what I'm asking.
I would suggest to surround your content with a
Kenijo thanks I appreciate it. I tried that but the user can still resize the grid to be smaller than the width of the field within the widget. I basically want to set the min height and min width of one widget. This would be a great addition to gridster. I'm sure I won't be the only person asking for it.
Hey Kenijo, can you take a look on my pull request, it adds min_height and min_width to a widget. https://github.com/ducksboard/gridster.js/pull/275 Best, Daniel
@dmattes: It looks great but I'm not part of this project, I can't do anything about it.
@ibarnes : Check this fiddle http://jsfiddle.net/RzLf5/7/ I get the width of the textbox and then use it to calculate the width of the widget the same way I did for the height.
Thanks.
Would be great to define the "min_size_x & min_size_y" of a widget like the corresponding "max_size_x & max-size_y" size restrictions.