Can't disable v-edit-dialog in Vue.js application - javascript

I have this v-edit-dialog below and even when the editMode is false the dialog box pops up!
I've also tried just setting the property to disabled like
:disabled="!editMode" => disabled
and it still pops up!
<v-edit-dialog :return-value.sync="props.item.productAnnotationText" large lazy persistent :disabled="!editMode" #save="inputAnnotation(props.item.productAnnotationText, props.item.id)">
<div>{{ props.item.productAnnotationText }}</div>
<div slot="input" class="mt-2 title">Update Annotation</div>
<v-text-field slot="input" v-model="props.item.productAnnotationText" label="Edit" single-line counter maxlength="50" autofocus :disabled="!editMode" color="#1976d2"></v-text-field>
</v-edit-dialog>

Try:
v-if="editMode"
Then it will 'go away' if edit mode it false.
or
Bind it to editMode. The value of v-model controls the visibility.
v-model='editMode'
Using v-model will also set editMode to false if the user closes the dialog.

The v-edit-dialog component doesn't have a 'disabled' prop so there is no way to stop it popping up if clicked. The only real option is to make the v-text-field disabled, as you already have, but this won't stop the dialog opening.
Apparently the vuetify team aren't fans of it.
There's a possibility that edit dialog will be removed in 2.0, so it's
not going to get much love

maybe i'm late for the party.
I wrapped v-edit-dialog with a div, with v-show .
<div v-show="editarRules">
<v-edit-dialog >
...
</v-edit-dialog>
</div>
and I have another div with the value I want t show, and the opposite condition in v-show.
Best Regards

How about some CSS?
Have a container with some class: "some-class".
Toggle the class like so: :class="'some-class': !editMode"
And then in CSS disable activating the edit dialog with: .some-class .v-small-dialog__activator { pointer-events: none; }

Related

Hide button on outside div tap

I'm trying to have a button no longer be show when the user isn't interacting with it or it's not the user's focus. I am using react right now in the project
In a desktop setting I accomplish this by saying onmouseleave={this.hideButton} but I'm having a tougher time with the iPad. I've tried onTouchCancel={this.hideButton} but haven't gotten lucky.
I looked at react documentation and see there's a touchTarget list, but I don't see any documentation on how to access these properties, am I going down the right path by looking trying to do it this way?
What I've tried before was having the body element listen with an onClick event and hide the button if it's showing but this didn't work as clicking on the button when it was showing would display the modal that I wanted to appear on button click.
I should also note that this.hideButton just changes a boolean value from true to false.
Any advice?
Note: This is a project for work where we've decided NOT to use jQuery (not my call)
Here is what it looks like currently:
toggleLogoutButton() {
this.setState({
logoutButtonVisible: this.props.shouldShowLogoutButton
&& !this.state.logoutButtonVisible,
});
}
logoutButtonAction() {
this.toggleLogoutButton();
this.props.showModal();
}
hideLogoutButton() {
if (this.state.logoutButtonVisible) {
this.setState({
logoutButtonVisible: false,
});
}
}
render() {
return(
<div className="some-style-1" >
<span
className="some-style-2"
onClick={this.toggleLogoutButton}>{this.props.text}
{this.props.shouldShowLogoutButton && this.caretRender()}
{this.state.logoutButtonVisible &&
<div className="dropmenu show"
onClick={this.logoutButtonAction}
onMouseLeave={this.hideLogoutButton}
onTouchEnd={this.hideLogoutButton}>
Log Out
</div>}
</span>
</div>);
}
Please include more pieces of your code!
In order to diagnose what you need, we need to see what you have already.
First off, change
onMouseLeave={this.hideButton};
to (assuming your button name has id="button-name"),
$('#button-name').onMouseLeave={this.hide()};
Depending on how you want your button to show/hide, I wouldn't suggest using this. Instead, turn the button to disabled=true. If you hide it, it will be gone and will no longer be able to be reached by onMouseEnter.
For example,
$('#button-name').onMouseLeave={this.disabled=true;};
With that said, hiding (and even disabled a button onMouseLeave...) does not make much sense.

How to display collapse when checkbox clicked in Ember bootstrap?

I'm fairly new to Ember and I'm trying to implement a Collapse method when I have clicked on a checkbox as a part of my form. This checkbox is inside a collapsed section part of a button group I have in my form.
Template.hbs
{{#bs-button onClick=(action "toggle")}}
{{#if collapsed}}
{{form.element controlType="checkbox" label="View Additional Fields" property="additionalFields"}}
{{/if}}
<div>
{{#bs-collapse collapsed=collapsed}}
{{form.element controlType="checkbox" label="Property" property="property"}}
{{form.element controlType="textarea" label="Instructions:" name="instructions" property="instructions"}}
{{/bs-collapse}}
</div>
{{/bs-button}}
Component.js
collapsed: true,
actions: {
toggle() {
let toggleValue = !get(this, 'collapsed');
set(this, 'collapsed', toggleValue);
}
}
When running ember serve and I go to my form if I click on the checkbox an error pops up in Ember Inspector:
Assertion Failed: You cannot use the form element's default onChange action for form elements if not using a model or setting the value directly on a form element.
You must add your own onChange action to the form element in this case!
Error
If I change onClick to onChange then fields aren't displayed when I click the checkbox, but I still get the error. What would be the best way to go about trying to fix this problem?
The error you are facing has nothing to do with {{bs-collapse}} or your {{bs-button}} onClick action. It seems like your {{bs-form}} does not have a model property but ember-bootstrap requires that one if you don't that an onChange action to each {{form.element}}. You find details in ember-bootstrap api docs and in source code.

ng-mouseover on disabled button in Angularjs

I want to use mouseover when the button is disabled. In the below code mouseover will work if ng-disabled="false" but it won't work if ng-disabled="true".
<body ng-app="ngAnimate">
<button ng-disabled="true" ng-mouseover="show=true" ng-mouseleave="show = false">
Mouseover
</button>
<div>
Show:
<span class="test" ng-show="show">
I show up when your mouse enter on button
</span>
</div>
</body>
It's not possbile. Actually it has nothing to do with Angular. It's expected behaviour when browsers are not supposed to fire onmouseover, onclick, etc. events on disabled form controls. So you can't do it directly.
Can't do it directly - meaning, that you can bind mouseover even to wrapping container which would not have this limitation. Then you would need to control action and proceed only if disabled flag is true or false if you need.
That being said, you should probably not try to workaround this behaviour. Form UX perspective disabled control should not be interaction-able, after all that's what disabled means.
I recently faced a similar problem where i disable a submit button on a form unless the form is valid. When the user hover over the disabled button, I wanted all required fields to get a different color.
I solved this using a html structure like this:
<div ng-class="{error: showError}">
<div disabled-wrapper ng-mouseenter="checkValid()" ng-mouseleave="showError = false">
<div><button ng-disabled="!valid">Next</button></div>
</div>
</div>
And css like this:
[disabled-wrapper] {
position: relative;
z-index: 0;
}
[disabled-wrapper] [disabled] {
position: relative;
z-index: -1;
}
And controller function:
$scope.checkValid = function() {
$scope.showError = !$scope.valid;
}
// I have more logic regarding validity of form.
// I am not sure why the div within the wrapper is needed (but it is).
// The positioning and z-index of the wrapper prevents any parent element with back-ground color from overshadowing the disabled button.

How to Programatically Toggle a Zurb Foundation Switch Control, in Chrome?

I would like to to dynamically toggle the state of a Zurb Foundation Switch control using javascript.
This is a default Zurb Fondation Switch:
<!-- Default switch -->
<div class="switch">
<input id="d" name="switch-d" type="radio" checked>
<label for="d" onclick="">Off</label>
<input id="d1" name="switch-d" type="radio">
<label for="d1" onclick="">On</label>
<span></span>
</div>
Demo here. They're based on this project, I believe.
When I tried to change the state of the switch using jquery:
$('#d1').attr('checked','checked'); $('#d').removeAttr('checked'); // Switch ON
$('#d').attr('checked','checked'); $('#d1').removeAttr('checked'); // Switch OFF
it worked in Firefox but not in Chrome. In Chrome [v25 on OSX10.8.3], the first command - Switch ON - is successful but when I try to use $('#d').attr('checked','checked'); $('#d1').removeAttr('checked'); then it looks like the CSS is not correctly picking up the element as being checked and the display balks - see how the last Switch in the image below is not displaying the OFF state properly.
You can test these commands on the Switch page of the Zurb Foundation documentation; d refers to the forth and largest switch you see in the list at the top of the page.
You can directly call the click function on the element.
$("#d1").click(); // Switch ON
The issue you will have is that the ID of the element changes so it will be slightly more tricky, you can use smarter selectors to get to the element.
Once the elements state has changed you will note that the ID has changed to:
$("#d").click(); // Switch OFF
This will now toggle you back into an off state.
Cheers Oliver.
Alternatively, if you are uncomfortable with simulating a click, you can use jQuery's #prop instead.
$('input:not([checked])').prop('checked', true);
$('input[checked]').prop('checked', false);
Possible use case: inside an error handler of an AJAX call that was fired on click.

Prevent checkbox from ticking/checking COMPLETELY

I have been asked to disable the "ticking" of a checkbox. I am not being asked to disable the checkbox, but to simply disable the "ticking".
In other words, a user will think that a checkbox is tickable, but it is not. Instead, clicking on the checkbox will cause a modal dialog to appear, giving the user more options to turn on or off the feature that the checkbox represents. If the options chosen in the dialog cause the feature to be turned on, then the checkbox will be ticked.
Now, the real problem is that for a split second, you can still see that the checkbox is being ticked.
I have tried an approach like this:
<input type='checkbox' onclick='return false' onkeydown='return false' />
$('input[type="checkbox"]').click(function(event) {
event.preventDefault();
alert('Break');
});
If you run this, the alert will appear, showing that the tick is visible (the alert is just there to demonstrate that it still does get ticked, in production, the alert is not there). On some users with slower machines and/or in browsers with slow renderers/javascript, users can see a very faint flicker (the flicker sometimes lasts for half a second, which is noticeable).
A tester in my team has flagged this as a defect and I am supposed to fix it. I'm not sure what else I can try to prevent the tick in the checkbox from flickering!
From my point of view it is as simple as:
$(this).prop('checked', !$(this).prop('checked'));
Works both for checked and unchecked boxes
Try
event.stopPropagation();
http://jsfiddle.net/DrKfE/3/
Best solution I've come up with:
$('input[type="checkbox"]').click(function(event) {
var $checkbox = $(this);
// Ensures this code runs AFTER the browser handles click however it wants.
setTimeout(function() {
$checkbox.removeAttr('checked');
}, 0);
event.preventDefault();
event.stopPropagation();
});
This effect can't be suppressed I fear. As soon as you click on the checkbox, the state (and rendering) is changed. Then the event handlers will be called. If you do a event.preventDefault(), the checkbox will be reset after all the handlers are executed. If your handler has a long execution time (easily testable with a modal alert()) and/or the rendering engine repaints before reseting, the box will flicker.
$('input[type="checkbox"]').click(function(event) {
this.checked = false; // reset first
event.preventDefault();
// event.stopPropagation() like in Zoltan's answer would also spare some
// handler execution time, but is no more needed here
// then do the heavy processing:
alert('Break');
});
This solution will reduce the flickering to a minimum, but can't hinder it really. See Thr4wn's and RobG's answer for how to simulate a checkbox. I would prefer the following:
<button id="settings" title="open extended settings">
<img src="default_checkbox.png" />
</button>
document.getElementById("settings").addEventListener("click", function(e) {
var img = this.getElementsByTagName("img")[0]);
openExtendedSettingsDialog(function callbackTick() {
img.src = "checked_checkbox.png";
}, function callbackUntick() {
img.src = "unchecked_checkbox.png";
});
}, false);
It is very important to use return false at the end.
Something like this:
$("#checkbox").click((e) => {
e.stopPropagation();
return false;
});
Isn't is simpler ? :
<input type="checkbox" onchange="this.checked = !this.checked">
TL:DR;
HTML api's execute before JavaScript. So you must use JavaScript to undo HTML's changes.
event.target.checked = false
WHAT is the problem?
Strictly speaking: we cannot "stop" the checkbox from being ticked. Why not? Because "being ticked" exactly means that the DOM's, HTML <input> element has a checked property value of true or false, which is immediately assigned by the HTML api
console.log(event.target.checked) // will be opposite of the previous value
So it's worth explicitly mentioning this HTML api is called before scripts. Which is intuitive and should make sense, because all JavaScript files are themselves the assignment of a <script> element's attribute src, and the ancestral relationship in the DOM tree, between your <input> in question, and the <script> element running your JavaScript, is extremely important to consider.
HOW to get our solution
The HTML assigned value has not yet been painted before we have a chance to intercept the control flow (via JS file like jQuery), so we simply re-assign the checked property to a boolean value we want: false (in your case).
So in conclusion, we CAN, in-effect, "stop" the checkbox from being checked, by simply ensuring that the checked property is false on the next render and thus, won't see any changes.
Why not simply add a class in your CSS that sets pointer-events: none;?
Something like:
<style>
input.lockedCbx { pointer-events: none; }
</style>
...
<input type="checkbox" class="lockedCbx" tabindex=-1 />
...
You need the tabindex=-1 to prevent users from tabbing into the checkbox and pressing a space bar to toggle.
Now in theory you could avoid the class and use the tabindex=-1 to control the disabling as in:
<script>
input[type="checkbox"][tabindex="-1"] { pointer-events: none; }
</script>
With CSS, you can change the image of the checkbox. See http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/ and also CSS Styling Checkboxes .
I would disable the checkbox, but replace it with an image of a working checkbox. That way the checkbox doesn't look disabled, but won't be clickable.
Wrap the checkbox with another element that somehow blocks pointer events (probably via CSS). Then, handle the wrapper's click event instead of the checkbox directly. This can be done a number of ways but here's a relatively simple example implementation:
$('input[type="checkbox"').parent('.disabled').click( function() {
// Add in whatever functionality you need here
alert('Break');
});
/* Insert an invisible element that covers the checkbox */
.disabled {
position: relative;
}
.disabled::after {
content: "";
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Only wrapped checkboxes are "disabled" -->
<input type="checkbox" />
<span class="disabled"><input type="checkbox" /></span>
<input type="checkbox" />
<span class="disabled"><input type="checkbox" /></span>
<span class="disabled"><input type="checkbox" /></span>
<input type="checkbox" />
Note: You could also add the wrapper elements programmatically, if you would like.
Sounds to me like you are using the wrong interface element, a more suitable one would be a button that is disabled by default, but enabled when that option is available. The image displayed can be whatever you want.
<button disabled onclick="doSomething();">Some option</button>
When users have selected that feature, enable the button. The image on the button can be modified by CSS depending on whether it's enabled or not, or by the enable/disable function.
e.g.
<script type="text/javascript">
function setOption(el) {
var idMap = {option1:'b0', option2: 'b1'};
document.getElementById(idMap[el.value]).disabled = !el.checked;
}
</script>
<div><p>Select options</p>
<input type="checkbox" onclick="setOption(this);" value="option1"> Option 1
<br>
<input type="checkbox" onclick="setOption(this);" value="option2"> Option 2
<br>
</div>
<div>
<button id="b0" onclick="alert('Select…');" disabled>Option 1 settings</button>
<button id="b1" onclick="alert('Select…');" disabled>Option 2 settings</button>
</div>
The Event.preventDefault method should work for change, keydown, and mousedown events, but doesn't in my testing.
My solution to this problem in a Mozilla Firefox 53.0 extension was to toggle an HTML class that enabled/disabled the CSS declaration pointer-events: none being applied to the checkbox. This addresses the cursor-based case, but not the key-based case. See https://www.w3.org/TR/SVG2/interact.html#PointerEventsProp.
I addressed the key-based case by adding/removing an HTML tabindex="-1" attribute. See https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex.
Note that disabling pointer-events will disable your ability to trigger CSS cursors on hover (e.g., cursor: not-allowed). My checkbox was already wrapped in a span element, so I added an HTML class to that span element which I then retargeted my CSS cursor declaration onto.
Also note that adding a tabindex="-1" attribute will not remove focus from the checkbox, so one will need to explicitly defocus it by using the HTMLElement.blur() method or by focusing another element to prevent key-based input if the checkbox is the active element at the time the attribute is added. Whether or not the checkbox is the focused element can be tested with my_checkbox.isEqualNode(document.activeElement).
Simply revert the value back
$('input[type="checkbox"]').on('change', function(e) {
if (new Date().getDate() === 13) {
$(this).prop('checked', !$(this).prop('checked'));
e.preventDefault();
return false;
}
// some code here
});
Add this to click event in js file
event.stopPropagation();
$('#term-input').on('change click',function (e){
e.preventDefault();
})
works for me

Categories