customizing size of form fields created using field.custom.widget - forms

I used the following code to generate a form in attached image.
Is it possible to change the size of the fields in the form.
I want to decrease size of input field of Estimated time and the dropbox field to the right of it
{{=form.custom.begin}}
<table>
<table><tr>
<td><b>Type :</b></td><td><div>{{=form.custom.widget.type}}</div></td>
</tr><tr>
<td><b>Title :</b></td><td><div>{{=form.custom.widget.title}}</div></td>
</tr><tr>
<td><b>Description :</b></td><td><div>{{=form.custom.widget.description}}</div></td>
</tr><tr>
<td><b>Estimated Time :</b></td><div'><td>{{=form.custom.widget.estimated_time}}{{=form.custom.widget.estimated_time_unit}}</td> </div>
</tr>
<tr>
<td></td><td><div align='center'>{{=form.custom.submit}}</div></td>
</tr>
</table>
{{=form.custom.end}}

Yes. You can and there are many ways.
The recommended way is to look at the generates JS. You will find it follows a naming convention described in the book. You can use CSS to change the look-and feel of every widget.
input[name=estimate_time] { width:50px }
Similarly you can use JS/jQuery (I would recommend you do this in the view).
jQuery(document).ready(function(){ jQuery('input[name=estimate_time]').css('width','50px');});
You can also use jQuery-like syntax in python in the controller:
form.element('input[name=estimate_time]')['_style']='width:50px'

Related

Find and Replace with Visual Studio Code to replace cell alignment with a class

Since the align attribute is considered obselete I am cleaning up code to remove it and replace with a CSS class. I'm trying to determine if there is a way to do this using find and replace (or something else) in VS Code.
As an example, I might have some html that looks like this:
<table>
<tr>
<td align="left" class="someclass" id="mainTitleCell" title="Title1">Title1</td>
<td align="center" title="Title2">Title2</td>
<td class="someclass" align="right" title="Title3">Title3</td> <!-- attributes are not always in the same order -->
</tr>
<tr>
<td align="left">Title</td>
<td align="center">Title</td>
<td align="right">Title</td>
</tr>
</table>
which I would like to change to
<table>
<tr>
<td class="left someclass" id="mainTitleCell" title="Title1">Title1</td>
<td class="center" title="Title2">Title2</td>
<td class="right someclass" title="Title3">Title3</td>
</tr>
<tr>
<td class="left">Content</td>
<td class="center">Content</td>
<td class="right">Content</td>
</tr>
</table>
Basically removing the align attribute and either adding a class attribute with a specific value OR adding a specific value to an existing class attribute. Is there a way to do this with the Edit...Replace option in VS Code? I know I can find based on a regex but not sure how I would go about the replace since this becomes
Find the align tag
Remove it
Find a class attribute in the <td> or <th> tag and add the appropriate class
If there is no class attribute, add one with the appropriate class.
Obviously step #1 & 2 are easy, it's #3 & 4 that I'm not sure of. I'd be totally happy with having to run 3 separate find and replace commands (one for left, center and right).
Do I have any options here (I am open to extensions)?
UPDATE:
#Mark had the right answer and I was able to chain together several find and replace commands using the Replace Rules extension. With that I can open a file, run a single keystroke to find and replace everything and clean up the extra spaces in the class attribute.
Try this:
Find: align="(.*?)"(.*?) class="(.*?)"|class="(.*?)"(.*?) align="(.*?)"|align="(.*?)"
Replace: class="$7$1$6 $3$4"$2$5
See regex101 demo.
I'm a little surprised this works as well as it does (I included a couple of other test cases you didn't). The only issue (thus far...) is that it can result in one stray space, as in:
<td class="left ">Title</td> // only happens when there is no class attribute
as you can see in the demo page. You could then search for " and replace with just ". It could be handled by a conditional replacement but vscode find/replace doesn't allow those.
To some degree attributes will be re-ordered so that the class attribute is first, but not always - you didn't mention that as a concern - any attribute that occurs before either the first class or align attribute will not be moved. Otherwise, attributes like id or title if they are between class<->attribute (in any order) will be put last.

DOM element not rendering html

I have built an html table that generates dynamically from a data array. It is intended to make a menu of beers on tap in my bar. The array contains the following data: [tap_number, brewery_image, beer_name, price_for_a_pint, price_for_a_pitcher]. Therefore the array dictates that the table generate with 5 columns and 14 rows (with current data). The image data consists of an html tagged image and similarly the beer_name is tagged <h3></h3>. All the html tagged data is rendering as text. What have I done wrong? btw, using Materialize css for basic table styling. Have tried with bootstrap also - same result. Here's a snippet of the html element that the js generates:
<table class = "tabel">
<thead>
<tr>
...has <td>column name</td> X5
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td><img src='[url of image]' alt=''></td>
<td><h3>[Beer_Name]</h3></td>
<td>$6</td>
<td>$10</td>
</tr>
...a bunch more rows..
</tbody>
</table>
.
So data positions 1 and 2 should be rendering according to html tag but are just appearing on the page as the text of their html. All data from the array is passed as textContent. Should I be using innerHtml? when I do, nothing at all renders. Cannot figure out what amateur mistake I've made or whether Materialize is screwing me... Thanks for any advice...
It was an amateur mistake. was using innerHtml instead of innerHTML....

Inject <thead> default with table in tinymce

I'm using Umbraco as the CMS, 7.6 - Umbraco.TinyMCEv3
So using insert Table will create HTML something like following
<table>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
How can I configure to add default <thead> when table is created
<table>
<thead>
<tr>…</tr>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
Thanks
I don't know if this is all that possible; it seems as though that functionality isn't included as a setting within the editor.
The obvious thing to do if the setting isn't included is to create it yourself - the way to to do this would be to either extend the existing editor or copy and paste the editor to a new one locally.
The files for the editor are under \Umbraco\lib\tinymce
Unfortunately, it appears the angular js file associated with this editor is only available as a non-human readable minified version - likely owing to the fact that tinymce is under license. So any modification of this would be quite tricky, to say the least.
Perhaps see if there is another way around this? You can always set css to select the first child row of the table if it is for styling purposes. Otherwise the only other option would be to create your table in the editor, then choose the code edit option to manually insert the correct table structure.
I have v5 with vue.js
After created table:
1-Click right on row of head you want > row > row properties
click right on row of head>row>row properties
2-In general choose "Header" at Row type
in general select of "Header" at Row type

Is it possible to have a table in the center in a GitHub gist Markdown?

Is it possible to have a table in the center in a GitHub gist Markdown? If so, how?
I've used the following syntax to create a table on a Markdown file:
Somehow the table is always flushed to the left!!!
|Column1|Column1|Column1|
|:----|:----:|----:|
|Column1|Column1|Column1|
But the table is flushed left, see https://gist.github.com/alvations/5095d3bcc0eec357c78f1c21a49e334f
Is it possible to have the table at the center of the page when viewing?
I've tried the suggestion from Is it possible to center tables in a markdown file? to use:
Somehow the table is always flushed to the left!!!
<center>
|Column1|Column1|Column1|
|:----|:----:|----:|
|Column1|Column1|Column1|
</center>
And the table disappears when viewing, see https://gist.github.com/alvations/cd3495e7107b7701cf1cf1da2a839534
I've also tried How do I center an image in the README.md on GitHub?:
Still on the left!!!
<p align="center">
|Column1|Column1|Column1|
|:----|:----:|----:|
|Column1|Column1|Column1|
</p>
But it's still on the left, see https://gist.github.com/alvations/23c18681df7a6bbf175d0e8c2cfccba3
Images for all three versions above:
In short, it's not possible. GitHub does not allow you to define your own styling.
First, note that there is no mention of the ability to apply any styling to any block level types in the GitHub Flavored Markdown spec (see the tables section). As your examples show, you are aware that you can center text within table cells, but that only applies to the cells and has no effect on the parent table (which is how HTML and CSS work and is not specific to Markdown or GitHub).
There are a few ways to define custom styles for HTML (which Markdown generates), but GitHub does not permit them.
One such way is to define CSS rules. However, right in the spec, GitHub explicitly states that they do not allow <style> tags.
Another way is to include raw HTML right in the Markdown document (with inline styles). However, for security reasons, GitHub is very selective about what they allow. In the Markup project they define the filters they apply to all markup languages they support (including, but not limited to Markdown). In pertinent part, the docs explain (emphasis added):
The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class or id attributes. See the sanitization filter for the full whitelist.
Given the above, it is simply not possible to define your own styling for documents hosted on GitHub. That said, some expect to be able to define styling within the Markdown syntax itself. However, the original Markdown rules explain (emphasis added):
Markdown’s syntax is intended for one purpose: to be used as a format for writing for the web.
Markdown is not a replacement for HTML, or even close to it. Its syntax is very small, corresponding only to a very small subset of HTML tags. The idea is not to create a syntax that makes it easier to insert HTML tags. In my opinion, HTML tags are already easy to insert. The idea for Markdown is to make it easy to read, write, and edit prose. HTML is a publishing format; Markdown is a writing format. Thus, Markdown’s formatting syntax only addresses issues that can be conveyed in plain text.
For any markup that is not covered by Markdown’s syntax, you simply use HTML itself.
As it is not a "publishing format," providing a way to style your document is out-of-scope for Markdown. Which leaves us with the ways which GitHub explicitly disallows. Therefore it is not possible to center a table (or apply any other custom styling) on GitHub.
As an aside, while GitHub uses the CommonMark spec (with extensions) rather than the original Markdown Rules, I make reference to the original rules as the section I quote from discusses the philosophy behind various design decisions made when creating Markdown. Markdown's (and CommonMark's) behaviors are directly related to that philosophy. While the CommonMark spec does not get into the design decisions (expect when it differs from Markdown), it does make reference to some of the points discussed in the very paragraph I quoted above. And nowhere does it contradict that philosophy. Therefore, I consider it relevant to the expectations we should have about what is and what is not part of CommonMark, and by extension, GitHub Flavored Markdown.
For completness, let's examine each of the examples provided by the OP.
The first example is simply a table with the middle column aligned "center". If we "view source" (or use the browser's "inspect" tool), we see the following HTML was generated:
<table>
<thead>
<tr>
<th align="left">Column1</th>
<th align="center">Column1</th>
<th align="right">Column1</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Column1</td>
<td align="center">Column1</td>
<td align="right">Column1</td>
</tr>
</tbody>
</table>
Note that align="center" is only defined on the middle cell of each row. As such styling is only inherited by children elements, not parent elements, this does not get applied to the the table as a whole.
As an aside, the align attribute is not even mentioned in the HTML5 spec (that I could find); however, in the HTML 4.01 spec, you can define an align attribute on a table element or any of its children which is then inherited by the children of that element only.
Of course as established above, Markdown does not provide a mechanism to define alignment on anything except the cells. But even if you could define align on the table element, the spec explains that "[t]his attribute specifies the alignment of data and the justification of text in a cell."
Therefore, if would still have no effect on how the table is positioned in its parent element.
The second example is a table wrapped in a <center> element. A look at the source HTML reveals that the <center> tag was stripped out.
In fact, a look at GitHub's whitelisted elements reveals that center elements are not allowed and stripped out.
The third example attempts to wrap the table in a paragraph with align="center" defined on the paragraph. However, note the (interpreted) HTML:
<p align="center"></p>
<table>
<thead>
<tr>
<th align="left">Column1</th>
<th align="center">Column1</th>
<th align="right">Column1</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Column1</td>
<td align="center">Column1</td>
<td align="right">Column1</td>
</tr>
</tbody>
</table>
<p></p>
According to the HTML5 spec:
A p element's end tag may be omitted if the p element is immediately followed by an... table... element.
Therefore, the paragraph does not actually wrap the table, but is implicitly closed by the table's opening tag.
But that got me curious. What if you used a div instead of a paragraph. But that makes no difference. As we've established earlier, the align attribute only effects cell text. You need to assign a style to change the position of a table on the page and Github explicitly disallows defining your own styles.
As you can see in the following image, GitHub automatically renders tables so that they're already taking up the full width. Because of this, you cannot center the text that GitHub's Markdown renderer generates (aka the table is really, really fat and technically already centered).
So totally possible !
 
<div align="center">
COLUMN 1 | </br>COLUMN 2 | </br></br>COLUMN 3
:--- | :---: | ---:
</br></br>left | center | </br></br>right
</div>
: Spacer
</br> : Skip line
:--- : Left
:---: : Center
---: : Right
It is possible to center a table. Essentially, on GitHub the table is already width 100%. You just need to give the tbody enough content for it take up 100% width too.
The trick: fill it with spaces.
<table>
<tbody>
<tr>
<td align="center">Key Features<br>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
</td>
<td align="center">Examples<br>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
</td>
<td align="center">Supported Methods<br>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
<span> </span>
</td>
</tr>
</tbody>
</table>
Result:
Narrow browser window:
Using mathjax:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML-full"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts:["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk:(MathJax.Hub.Browser.isMobile ? 10 : 50) }, tex2jax: { inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" }, TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } }, messageStyle: "none" }); </script>
$$
\begin{array}{|c|c|c|}
\hline
\textbf{Column1} & \textbf{Column1} & \textbf{Column1} \\
\hline
\text{Column1} & \text{Column1} & \text{Column1} \\
\hline
\end{array}
$$
Just add align="center" into tag table
<table align="center"></table>

Nesting dynamically displayed components in wicket

I have a need to create following kind of markup with wicket using ajax:
<table>
<tr>
<td><a>first</a></td>
<tr>
<tr>
<td>displayed/closed if first is clicked <a>open</a></td>
</tr>
<tr><td>this and following displayed/closed if above open is clicked</td></tr>
<tr><td>there may be any number of these</td></tr>
<tr>
<td>there may be any number of these as well <a>open</a></td>
</tr>
<tr>
<td>any number of these as well <a>second</a></td>
</tr>
</table>
How to use ListViews or some other wicket element to individually toggle open "inner" rows of the table. I don't want to resort to render everything and toggling visibility but really create the rows in server side only when expand is requested. The markup should also be valid xhtml (rules out arbitrary container for row groups). I know I can put multiple tbodys, but it's good enough only for one level of nesting (no .... allowed).
From Lord Torgamus' comment, the ajax tree sounds appropriate..