Is there a way to fire an event on the last select element in cofeescript - coffeescript

I work on a project which uses coffeescript, I have to generate a select element (combobox) dynamically, I generate it. But I want to fire an event on the last select element, but it doesn't work, I wrote like this.
$("select:last").change ->
But it fires the event only when I change the first select element.

Have you tried using the on event?
$('select:last').on 'chnage', ->

For those who have the same problem, you can do like this $(document.body).on 'change', 'select:last', ->

The code you wrote looks correct. Is the body of the method indented properly? It should be one tab further to the right than the line you posted.
I would try making some of the syntax more explicit to rule out weird issues related to tabbing:
$("select:last").change{ () -> }

Related

How to clear MUI Autocomplete to initial state

I would like to reset/clear my MUI Autocomplete component.
I have two of them with model like { label: string, value: string } and if first will change its value then I would like to clear the second one since second will get options by selected value in first one.
Moreover - I am using react-hook-form with setValue. I use as value in this method { label: '', value: '' } but it causes warning that in my new sort of options there is no such option to select (this is minor issue I think) but it does not reset second Autocomplete input but partially. I still see X to clear value. I used null as value in setValue but it does not cleat input as well.
What I want to achieve is - selecting some option on first input I would like to reset second input like clicking on X does. Is it possible ?
Cheers!
I found what caused the issue I describe above. It was because Autocomplete in my codebase was declared with clearOnBlur={false} props. It prevented to clear value of my Autocomplete when I was doing setValue(autocompleteFieldName, null) via react-hook-form. I hope it helps someone with the same strange issue since I was not interacting with input at all to invoke onBlur event. Cheers!

Get func placeholder values from a snippet to appear after hitting tab at top level code level

New to swift and xcode, version 11.3.1.
If I hit func<tab> in a class, the placeholder values pop in nicely and I can tab through them to complete them.
However, when I have a simple playground file open and hit func<tab> I don't see any placeholder values. Just the keyword func appears.
How do I turn on these placeholder values for top-level functions?
What you are talking about are "code snippets". You can insert them not only by typing the "magic word", but also by clicking on the plus sign on the top right, then choosing from the list:
If you search for "Function", you can find the one you're looking for.
But who wants to click a button when writing code, right? It seems like some of the snippets somehow can't be used in playgrounds, while others can. This seems like an Xcode bug. For me, things like var, varget, vargetset all worked.
As an workaround, you can create your own code snippet for a function. First, paste this code into Xcode:
func <#name#>(<#parameters#>) -> <#return type#> {
<#function body#>
}
Select all of it, then go to Editor -> Create Code Snippet. Give it a name, and most importantly, a "Completion".
Apparently, you can still put func as the "Completion" and it will work.
I'm not sure if there is a better answer but here is what worked to get the func snippet to show up while editing a "playground" file:
1) Edit snippets file with: sudo vim /Applications/Xcode.app/Contents/PlugIns/IDESourceEditor.framework/Versions/A/Resources/SystemCodeSnippets.codesnippets
2) Search for snippet and find the related scope key and modify the array of the scope key to <string>All</string>:
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>All</string>
</array>
Yes, I could create my own snippet which is the same as the built-in snippet but then I have two different snippets that do the same thing, which I found annoying.

Eclipse shortcut - generate some a method from some code

is there a shortcut to generate a method, when selecting a piece of code in my program? Sth like encapsule code or sth like that. Does that exist in eclipse? I cannot find anything in the help section.
I really appreciate your answer!
In order to move a code part to a method you have to do the following:
select the code which should be extracted
Right click and select: Refactor -> Extract Method
in the option window: enter a method name and click OK

Testing modal dialogs with zombie.js

I have some input fields inside a modal dialog like so (that's jade):
.modal-body
.control-group
label.required(for="event-planner-email")= Email
.input
input#event-planner-email(name="email", type='text')
.control-group
label.required(for="event-planner-name")= Name
.input
input#event-planner-name(name="name", type='text')
And I would like to be able to fill them out in a test. I tried pressing the link that opens the modal and filling the fields using zombie.js browser object, code in coffee follows:
browser.clickLink 'a#open-planner', () ->
browser
.fill('event-planner-email', someEmail)
.fill('event-planner-name', someName)
.pressButton 'Create', () ->
do done
But I get an error saying: "No INPUT matching 'event-planner-email'". If anyone knows how to do this, help would be much appreciated. Thanks!
Maybe the modal has not come into view yet by the time your call back is firing. If there is a transition happening to show the modal, you'll have to wait for that transition to complete.
Maybe try adding a setTimeout in your call back of the clickLink:
browser.clickLink 'a#open-planner', ->
fillForm = ->
browser
.fill('event-planner-email', someEmail)
.fill('event-planner-name', someName)
.pressButton 'Create', ->
do done
setTimeout fillForm, 1000
From the Bootstrap docs
You need to run your zombie code after the modal loads, so you should use the "shown" event
$('#myModal').on('shown', function () {
// zombie
})
I'm not sure how to represent that in coffee
Thanks everyone, turns out I just didn't use the proper css selector for the input elements, so instead of
.fill('event-planner-email', someEmail)
should be
.fill('input#event-planner-email', someEmail)
Because in jade snippet above, 'event-planner-email' is the id of the input element. Wanted to delete my question, so that I don't expose my stupidity any further, but apparently it's too late.

I'm trying to select the adjacent sibling of "this" in jquery

$(this+"p").slideDown("slow");
$(this)+$("p").slideDown("slow");
$("this+p").slideDown("slow");
does not work.
Yeah, your syntax is bad. You should use the jQuery Sibling function:
$(this).siblings().find("p").slideDown("slow");
The jQuery API site is awesome for looking stuff like this up, I rely on it nearly daily. I'd keep an eye on it.
Next.
$(this).next("p").slideDown("slow")
Make sure that the "p" element is directly adjacent, though. Otherwise you'll want to use nextAll.
jQuery have not seemed to apply this? Possibly the syntax we are trying to use is incorrect.
next() can only select elements with an ID or Class - Not just a naked dom element as expected.
Instead use. > means select first level decends only.
$('body > div').hide();
But this gives the exact same result
$('body').children('div').hide();
But,
Next
$('body + div').hide();
and
Previous
$('body ~ div').hide();
Do not seem to work as expected? But jQuery use it as example for CSS selection...
Possibly there is a complex syntax to achieve this but I could not figure it out...