[OPEN] [#1362] [4.1.0] FieldTrigger - Handler - Literal string newline - bug

  1. #1

    [OPEN] [#1362] [4.1.0] FieldTrigger - Handler - Literal string newline - bug

    Hi, the generated javascript will be invalid if a FieldTrigger handler is a literal string with newline in it:

    @{ 
        var x = Html.X(); 
    }
    
    @(    
        x.TextField()
            .Triggers(
                x.FieldTrigger()
                    .Icon(TriggerIcon.Ellipsis)
                    .Handler(@"
                        alert('test');
                    ")
            )
    )
  2. #2
    Hello!

    If you need a more comprehensive javascript bound to your field's trigger buttons, please use a full listener.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Yes, I do that as a workaround. But the strange behavior described is different from the behavior of other handlers in the library. I have never had problems using the Handler function like this other places, or other "inline" functions. The javascript has never got invalid because of newline in literal c# strings. Besides, in the newer examples from Sencha they use the handler-config on FieldTriggerstriggers. And the TriggerClick-event is not even there:

    http://docs.sencha.com/extjs/6.0.1-c...l#cfg-triggers

    There is a workaround like you say, to use the TriggerClick-event. But it will result in more code. First, each triggers must have a Tag to be identified, second the event-handler must have if-s in it to check which trigger has been clicked based on that Tag.
    Last edited by sveins12; Jul 25, 2016 at 10:11 PM.
  4. #4
    Hello @sveins12!

    Well, after all, there's a conversion error there when it outputs JavaScript code with "invented" backslash plus 'n' characters, where that should be the line break itself.

    So, please stick to the workaround for now. Actually, I'd advice you (this is not a rule though) to avoid javascript under quotes, as it just makes it hard for you and your team to debug the code. Instead, you may define functions inside JavaScript script blocks in HTML (or .js files) and in addition to what's already said, get nice syntax hilighting, auto indent and code completion -- at least from Visual Studio. As well as leaving the component definition code as small as possible.

    Well, at least I believe what you get in your example withing VS is something similar to this:
    Click image for larger version. 

Name:	61320-plaintextblock.png 
Views:	61 
Size:	5.1 KB 
ID:	24701

    Anyway, yes, we've logged the issue, your test case is so simple and reproduces the issue so clearly that well, I got no arguments against logging an issue to fix this!

    That said, issue #1362 has been logged in our issues tracker. We're going to update here as soon as we get that piece of code fixed!

    Thanks for taking your time to not only report the issue, but support the need and usefulness in fixing it!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    No problem :)
    Last edited by sveins12; Jul 27, 2016 at 1:26 AM.

Similar Threads

  1. Replies: 2
    Last Post: Jun 16, 2016, 3:48 PM
  2. [CLOSED] X.Msg.Show with newLine characters
    By extnetGA in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 19, 2015, 4:36 PM
  3. Replies: 0
    Last Post: Nov 15, 2013, 9:32 AM
  4. Replies: 6
    Last Post: Sep 02, 2010, 5:36 AM
  5. New line character literal in message box
    By kumarxlnt in forum 1.x Help
    Replies: 4
    Last Post: Sep 30, 2009, 9:23 AM

Posting Permissions