WebStorm - Indent JSX elements inside curly braces - webstorm

I am trying to configure WebStorm 2018.2.5 to achieve this:
{ showButton &&
<Button />
}
But WebStorm auto-indents to this:
{ showButton &&
<Button />
}
I tried to configure HTML and JavaScript rules of the IDE, but failed to achieve the desired result.
The style I am trying to configure is suggested by AirBnB, but I am not interested in applying all of its rules.

It's not currently possible, please follow WEB-25338 for updates

Related

Adding next and previous links to an automatic slideshow

I've incorporated the following automatic slideshow into a webpage that I'm developing...
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow_auto
...but would like the ability to manually move to the next slide or go back as shown here...
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow
W3schools provide both types of slideshows (manual and automatic) but not one where the manual and automatic features are combined. I've tried incorporating the CSS and JS of one in to the other but can't get it to work - presumably because both JS scripts are calling on the same functions. Can anyone help?
Add two links to HTML :
<a id="prev" href="#" >Prev</a>
<a id="next" href="#" >Next</a>
JS:
$("#next").click(function(){
$('#slideshow > div:first-child')
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo('#slideshow');
});
$("#prev").click(function(){
$('#slideshow > div:first-child')
.fadeOut(1000)
$('#slideshow > div:last-child')
.prependTo('#slideshow')
.fadeOut();
$('#slideshow > div:first-child').fadeIn();
});

How to fix "react/jsx-closing-bracket-location" in WebStorm

How to fix react/jsx-closing-bracket-location issue in WebStorm(Idea, PhpStorm, etc)?
The problem:
getElem(name) {
return (<input type="text"
value={this.state.value}
/>);
}
This block will produce an error:
The closing bracket must be aligned with the opening tag (expected
column 13) react/jsx-closing-bracket-location
(docs for react/jsx-closing-bracket-location)
Same block without that problem:
getElem(name) {
return (<input type="text"
value={this.state.value}
/>);
}
P.S. I'm not allowed to modify eslint rules
You can't configure WebStorm to automatically format your code according to this rule, here's a related feature request: https://youtrack.jetbrains.com/issue/WEB-19721
But WebStorm won't break your formatting if you already have a code formated like that.
You can either format it like that manually or use ESLint --fix option (hit alt-enter on the error and select Fix with ESLint or run eslint --fix filename in the terminal).
I was facing this same problem. Here was my code:
<input
className="input__field input__field--haruki"
type="text" id="input-1"
onFocus={this.onFocus}
onBlur={this.onBlur}/>
To work I did that:
<input
className="input__field input__field--haruki"
type="text" id="input-1"
onFocus={this.onFocus}
onBlur={this.onBlur}
/>
Just created a new line with the /> aligned with the original tag.

Using Updatepanel in sharepoint 2013 web part

We are facing problem related to updatepanel in sharepoint 2013. we have a sample webpart that includs a label and a button, we want to write somthing to label in click event of button without refreshing the whole page. Our sample code is as followed :
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
<asp:Label ID="lbl" runat="server" Text="Loaded" Visible="true"></asp:Label>
<asp:Button ID="btn" runat="server" OnClick="btn_Click"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
protected void btn_Click(object sender, EventArgs e)
{
lbl.Text = "BUTTON CLICKED !";
lbl.Visible = true;
}
We have tried the solution mentioned on this link but could not achieve our goal.
Any solution for this problem along with sample code will be highly appreciated.
Thanks.
As I noticed the Content Search webpart and the update panel cannot work together on SharePoint 2013 for some reason. If I add my custom update panel webpart to stand alone page than working the updapanel well.
Have you tried to play with UpdateMode and ChildrenAsTriggers? Like this for example:
<asp:UpdatePanel id="UpdatePanel1" runat="server"
UpdateMode="Conditional" ChildrenAsTriggers="true" >

Sugarcrm : How to rewrite a document URL

My version :
SugarCRM CE 6.5.2 running on linux
What I want to do :
I've customized the Documents module in "custom/modules/Documents" by writing several logic hooks.
These logic hooks creates new folders in "ressources/" which is my new upload folder. (I've change the 'upload_dir' from "./upload" into "./ressources" in the config.php)
This is done through a custom field created in studio named "folder_name"
And then, the logic hooks cut and paste the document uploaded into this new folder.
What is my problem
So, with all of this, my download url in Edit, Detail and Revisions Subpanel Views is false. I would like to change it to the right folder, like, for example adding a folder parameter in the url
like this :
/index.php?entryPoint=download&folder=Images&id=idDoc&type=Documents
I tried to change the a href link in EditView.tpl or DetailView.tpl, (like )
but it didn't work since they were located in my cache/modules/Documents folder and were overriding when i did a quick repair.
So I copies/pasted the DetailView.tpl and the EditView.tpl into custom/modules/Documents/tpls and tried to override the view.edit.php and the view.detail.php to link the customized templates, but it did not work.
code :
<?php
require_once('include/MVC/View/views/view.detail.php');
class DocumentsViewDetail extends ViewDetail {
function DocumentsViewDetail() {
parent::ViewDetail();
}
function display() {
parent::display();
}
function detailViewProcess() {
$this->processSearchForm();
$this->lv->searchColumns = $this->searchForm->searchColumns;
if (!$this->headers)
return;
if (empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false) {
//here we are overriding with your custom template
$this->lv->setup($this->seed, 'custom/modules/Documents/tpls/DetailView.tpl', $this->where, $this->params);
echo $this->lv->display();
}
}
}
?>
Do you have any idea why this doesn't work?
Do you have any idea on how i could rewrite my URLS or override the Edit, Revisions SubPanel and Details Views?
Please answer, this is URGENT
Thank you by advance.
Try adding the folder parameter to the variable $file_url inside the method fill_in_additional_detail_fields() in modules/Documents/Document.php.
[Edited]
EditView: include/SugarFields/Fields/File/EditView.tpl
DetailView: include/SugarFields/Fields/File/DetailView.tpl
<a href="index.php?entryPoint=download&id={$fields.{{$vardef.fileId}}.value}&type={{$vardef.linkModule}}&folder=test" ...
ListView: include/SugarFields/Fields/File/ListView.tpl
<a href="index.php?entryPoint=download&id={$parentFieldArray.ID}&type={$displayParams.module}{$vardef.displayParams.module}&folder=test" ...
So, thanks to #air4x, i did answer my trouble : overriding the DetailView.tpl
To make it upgrade-safe, i copies it from
include/SugarFields/Fields/File/DetailView.tpl
to
custom/include/SugarFields/Fields/File/DetailView.tpl
It works!
BUT there is a big trouble coming...
explanations :
1] I create a new Document, uploading image01 to Folder01. Save. Database ok. in DetailView the folder name is "Folder01" and the link '//Folder01/image01_id' works.
2] I create another new Document, uploading image02 to Folder02. Save. Databse ok. BUT in DetailView the folder's name is not "Folder02" but "Folder01". AND the link is //Folder01/image02_id so it doesn't work, because in database or in my folders, the file is still in Folder02.
Here is my custom/include/SugarFields/Fields/File/DetailView.tpl code :
//BEGIN the code i modified
<span class="sugar_field" id="{{if empty($displayParams.idName)}}{{sugarvar key='name'}}{{else}}{{$displayParams.idName}}{{/if}}">
<a href="ressources/{$fields.folder_name_c.value}/{$fields.{{$vardef.fileId}}.value}" class="tabDetailViewDFLink" target='_blank'>{{sugarvar key='value'}}</a>
</span>
//END the code i modified
{{if isset($vardef) && isset($vardef.allowEapm) && $vardef.allowEapm}}
{if isset($fields.{{$vardef.docType}}) && !empty($fields.{{$vardef.docType}}.value) && $fields.{{$vardef.docType}}.value != 'SugarCRM' && !empty($fields.{{$vardef.docUrl}}.value) }
{capture name=imageNameCapture assign=imageName}
{$fields.{{$vardef.docType}}.value}_image_inline.png
{/capture}
{sugar_getimage name=$imageName alt=$imageName other_attributes='border="0" '}
{/if}
{{/if}}
{{if !empty($displayParams.enableConnectors)}}
{{sugarvar_connector view='DetailView'}}
{{/if}}
I really don't know why my $fields.folder_name_c.value stay from the first document and replace the one in the second document...
Do you know how i could do a sql query in my EditView.tpl to change it and have the right value?
Please, i really need help.
Thank you
(ps : #air4x, thanks a LOT, even if i have another trouble, that showed me hox to override EditView. THANK YOU! )

Sitecore Field Renderer - add markup inside rendering

As part of an SEO enhancement project, I've been tasked with adding the following property inside the markup for the image that the field renderer is generating on the page:
itemprop="contentURL" - before the closing tag.
<sc:FieldRenderer ID='FieldRenderer_MainImage' Runat='server' FieldName='Homepage Image'
CssClass="_image" Parameters="w=150" itemprop="contentURL" />
When I tried to place this inside the Field Renderer, or add it as a "parameter" - it doesn't work.
Is there another way to do this, without having to create a control file and generate the output in the code-behind?
You need to use the "Parameters" property for setting extra properties on both the and control.
You can to it like this :
<sc:FieldRenderer ID="PageImage" runat="server" FieldName="ContentImage" Parameters="ControlType=C4Image&rel=relString" />
<sc:Image ID="SCPageImage" runat="server" Field="ContentImage" Parameters="ControlType=C4Image&rel=relString" />
That will be rendered like this :
<img width="1232" height="637" controltype="C4Image" rel="relString" alt="" src="~/media/Images/DEMO backgrounds/background2.ashx">
Note: This works in 6.5 and 6.6 - not sure which version is being used in this question.
Couldn't this be done by extending the RenderField pipeline? You could potentially decompile (using Reflector or ILSpy) the GetImageFieldValue and add your own logic to adjust the output from the ImageRenderer?
Reference Sitecore.Pipelines.RenderField.GetImageFieldValue.
In cases where "Parameters" doesn't work or trying to create a Custom control, and instead of wrapping the control in a classed div like this:
<div class="my-class">
<sc:FieldRenderer runat="server" />
</div>
You can use this:
<sc:FieldRenderer Before="<div class='my-class'>" After="</div>" runat="server" />
Notice the Single quotes in the class declaration of the div above.
This keeps it a little cleaner and in context with the Sitecore control instead of a Web Developer adding an external div that might later lose its context if changes occur.
I recommend saving yourself some trouble and using the MVC version of Sitecore though, now, (when starting new Sitecore projects), as you can very simply add a class to it like so:
How can I get Sitecore Field Renderer to use a css class for an image
You actually cannot do this on a FieldRenderer. You're options are:
Extend the FieldRenderer with the ability to do this (this will likely require a high level of effort)
Use a regular .NET control and bind the data from the Sitecore item via the C# code-behind.
You may want to try using the <sc:image /> tag.
If you add a custom parameter there, it's added as an attribute to the img tag.
In your case the tag will look like this:
<sc:image runat="server" field="Homepage Image" width="150" itemprop="contentURL" class="_image" />
using mvc, I found this was easier than extending the FieldRender, should be reusable, but will have to test a bit more. WIP.
var image = "<span class=\"rightImage\">" + FieldRenderer.Render(contentBlock, "Image", "mw=300") + "</span>";
var text = FieldRenderer.Render(contentBlock, "Text");
model.Text = FieldRendererHelper.InjectIntoRenderer(text, image, "<p>");
public static HtmlString InjectIntoRenderer(string parentField, string injectField, string injectTag)
{
return new HtmlString(parentField.Insert(parentField.IndexOf(injectTag, StringComparison.InvariantCulture) + injectTag.Length, injectField));
}