question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Quasar props can not contain spaces

See original GitHub issue

Discussed in https://github.com/zauberzeug/nicegui/discussions/97

<div type='discussions-op-text'>

Originally posted by gbrandt September 27, 2022 I am using ui.input() and it allows a prop called ‘error-message’.

self.input_add_user_email = ui.input(label='Email', on_change=self.on_change_email).props('error-message=Invalid Email').style('width: 300px')

However only the text Invalid is shown on the error when I do this: self.button_add_user.props('disable=false')

Is there anyway to get a string with spaces into the error message?</div>

This is indeed a limitation of our current simple property parsing: https://github.com/zauberzeug/nicegui/blob/f417d7a64b43f00e52dd843445a8a9d8b9b366b9/nicegui/elements/element.py#L93

Task List:

  • write integration test (skip execution until issue is fixed)
  • unit-test str_to_dict function which is used by element.props
  • allow multi-word values in props
  • enable integration test if everything is running
  • review

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
falkoschindlercommented, Sep 28, 2022

Inspired by the gist I came up with quite simple parsers for props, styles and classes:

def parse_props(text: str) -> Dict[str, str]:
    lexer = shlex.shlex(text, posix=True)
    lexer.whitespace = ' '
    lexer.wordchars += '=-'
    return dict(word.split('=', 1) if '=' in word else (word, True) for word in lexer)

def parse_style(text: str) -> Dict[str, str]:
    lexer = shlex.shlex(text, posix=True)
    lexer.whitespace = ';'
    lexer.wordchars += ':- '
    return dict(map(str.strip, word.split(':', 1)) for word in lexer)

def parse_classes(text: str) -> Set[str]:
    lexer = shlex.shlex(text, posix=True)
    lexer.whitespace = ' '
    lexer.wordchars += '-'
    return set(lexer)

print(parse_props('error error-message="Invalid & Email"'))
print(parse_style('bg-color:red; foo:bar'))
print(parse_classes('foo bar-buz one_two'))

Each lexer defines whitespace that separates consecutive key-value blocks. wordchars are letters, numbers and “_” by default. We the key-value separator and other allows characters like “-”. Note that everything in quotes is allowed anyway, like the “&” in the props example. The last step is to process the lexing result: Props are automatically true if not value is given; and we strip whitespace from style keys and values.

These functions could replace str_to_dict. And the lexers could even be instantiated once and reused if performance is an issue.

0reactions
rodjacommented, Oct 5, 2022

Bugfix release in 0.9.11

Read more comments on GitHub >

github_iconTop Results From Across the Web

QSpace - Quasar Framework
The purpose of QSpace (has no props) is to simply fill all available space inside of a flexbox DOM element. As a sidenote,...
Read more >
white-space: pre-wrap doesn't work while passing text as a ...
I am just passing a long-text as a prop into a child component in Vue project. child component ...
Read more >
Quasar's QTable: The ULTIMATE Component (2/6)
I use selectable rows, and expandable rows all the time! I'll give you a real world example. We record "spraying events" for paddocks, ......
Read more >
Vuelidate | A Vue.js model validation library
This is especially useful if you are using data from external source, like Vuex store or props. In that case you have to...
Read more >
Available rules - eslint-plugin-vue
Rule ID Description vue/multi‑word‑component‑names require component names to be always multi‑word... vue/no‑arrow‑functions‑in‑watch disallow using arrow functions to define watcher... vue/no‑computed‑properties‑in‑data disallow accessing computed properties in data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found