how to disable special characters text field in sugarcrm? - sugarcrm

can anyone help me in this issue.
I want to avoid special characters(!##$%^&*()) in text field.
Actually I have added javascript code for this.
now I cant enter the spl characters. it's working perfect.
But the problem is, the data is not going to be inserted after submitted.
<script language="Javascript" type="text/javascript">
function alpha(e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}
</script>
'customCode' => '<input type="text" onkeypress="return alpha(event)">',

You have missed the name of textfield in customCode. Your customCode should be like:
'customCode' => '< input type="text" onkeypress="return alpha(event)" name="your-textbox-name">',

Related

using Perl range operator for html table

I'm having issues with the Perl range operator when assigning a range to my variable.
I have an HTML table that outputs numbers from a SQL query. How can I add a range from 98-99 to color code the data yellow?
I have this working for other cases (<100 and >100) but can't seem to get the 3rd option to work.
Thank you in advance for helping!!!
my $highlightProjMoves3300red = ($variableProjMoves3300 < 100) ? ' STYLE="COLOR:RED"' : '';
my $highlightProjMoves3300green = ($variableProjMoves3300 > 100) ? ' STYLE="COLOR:GREEN"' : '';
my $highlightProjMoves3300yellow = ($variableProjMoves3300 = (98..99)) ? ' STYLE="COLOR:YELLOW"' : '';
<tr>
<td>GATE</td>
<td>3300</td>
<td>$variable3300</td>
<td>$variableYTRG3300</td>
<td $highlight3300>$variableYESTDELTA3300</td>
<td>$variableDTDMOVES3300</td>
<td $highlightProjMoves3300red $highlightProjMoves3300green $highlightProjMoves3300yellow >$variableProjMoves3300%</td>
<td>$variablePASTWEEKMOVES3300</td>
<td></td>
<td></td>
<td></td>
<td>$variableCURRENT_WIP_GATE</td>
</tr>
Your approach is failing because the range operator generates a list of values. Comparing a variable to a list doesn't give you a true result if the list contains the value.
You'd need to search for it.
#!/usr/bin/perl
use v5.20;
use warnings;
use List::MoreUtils qw(any);
my #values = (50, 98, 200);
foreach my $variableProjMoves3300 (#values) {
if (any {$_ == $variableProjMoves3300} (98..99)) {
say "$variableProjMoves3300 is between 98 and 99 (inclusive)";
}
}
This isn't an approach I'd recommend though, at least not for dealing with the case "between two numbers".
A traditional
if (98 <= $variableProjMoves3300 && $variableProjMoves3300 <= 99) {
… is clearer and (I expect) faster.
98 <= $variableProjMoves3300 <= 99 # 5.32+
or
98 <= $variableProjMoves3300 && $variableProjMoves3300 <= 99
That said, having a collection of variables make no sense. You want to set the style based on the number of moves, so you need one variable for the style.
my $highlightProjMoves3300Style =
$variableProjMoves3300 < 98 ? ' STYLE="COLOR:RED"'
: $variableProjMoves3300 < 100 ? ' STYLE="COLOR:YELLOW"'
: $variableProjMoves3300 == 100 ? ''
: ' STYLE="COLOR:GREEN"';
Or if you didn't mean to skip 100,
my $highlightProjMoves3300Style =
$variableProjMoves3300 < 98 ? ' STYLE="COLOR:RED"'
: $variableProjMoves3300 < 100 ? ' STYLE="COLOR:YELLOW"'
: ' STYLE="COLOR:GREEN"';

Date range in query Dynamics AX

I would like to build query Range, where
ActiveTo < today || ActiveFrom > today.
Is it possible, I tried something like that but it's not working.
qbdsDimAttrValue = ds.addDataSource(tableNum(DimensionAttributeValue));
qbrMainAccountActiveFrom = qbdsDimAttrValue.addRange(fieldnum(DimensionAttributeValue,ActiveFrom));
qbrMainAccountActiveFrom.value(strFmt('(((%1.%2 != 0) || (%1.%3 != 0)) && ((%1.%2 > %4) || (%1.%3 < %4)))',
qbdsDimAttrValue.name(),
fieldStr(DimensionAttributeValue,ActiveFrom),
fieldStr(DimensionAttributeValue,ActiveTo),
today(),
));
I write 0, because in table DimensionAttributeValue if field ActiveFrom, ActiveTo is null it has value 0, not dateNull(), dateMax()
Date values used in such queries must be in the dd\MM\yyyy format - you can use function date2StrXpp() for this purpose.
Try using the following range:
qbrMainAccountActiveFrom.value(
strFmt('((%1.%2 > %4) || ((%1.%3 < %4) && (%1.%3 != %5)))',
qbdsDimAttrValue.name(),
fieldStr(DimensionAttributeValue, ActiveFrom),
fieldStr(DimensionAttributeValue, ActiveTo),
date2StrXpp(systemDateGet()),
date2StrXpp(dateNull())
));
If you check Global::dateNull() you will see that it returns '01\01\1900', also you can see that database doesn't store 0 in these fields:
Yo can find more details here
So you can simplify your extended range as follows
qbrMainAccountActiveFrom.value(strFmt('((%1.%2 > %4) || (%1.%3 < %4))',
qbds.name(),
fieldStr(DimensionAttributeValue, ActiveFrom),
fieldStr(DimensionAttributeValue, ActiveTo),
today()
));

Group typo3 condition

I need such a condition in ts:
([treeLevel = 0] && [globalVar = GP:R > 0]) || [PIDinRootline = {$pages.2018}]
I wanna show block if page has treelevel=0 and the get var R > 0, or if page id = $pages.2018
It looks like the similar code in php:
if(($treeLevel == 0 && $r > 0) || (pid == number))
The all expression in first brackets should be right, or in second.
Is it exist the method to group it like the previous record or I can only use userfunc?
There is no grouping in TS conditions, but if you need this particular condition from your post I think it is not needed because brackets around && are useless in this case.
(p && q) || r
is exactly the same as
p && q || r
Did you tested it?

Using charcode to allow only numbers and enter key

I have this syntax:
<input onkeypress="return event.charCode >= 48 && event.charCode <= 57">
I use it on inputs to allow only numbers.
But now i need to allow the enter key too since i can no longer use a button to submit the form(personal reasons).By now i found this:
event.charCode = 13 // allows enter key
but i can't seem to find how to build the onkeypress syntax.Any help ? Thank you.
you can try:
onkeypress="return event.charCode >= 8 && event.charCode <= 57"
In this way you can allow enter key,numbers..and few other characters,except for alphabetic characters.I don't see any other way.
Source: click
You might try:
onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 13"
event.charCode >= 48 && event.charCode <= 57 is for numbers 0-9
event.charCode == 13 is for enter
If you do something like:
onkeypress="return event.charCode >= 8 && event.charCode <= 57"
and you want the user to be able to delete or backspace make sure you include:
onkeypress='return event.charCode >= 48 && event.charCode <= 57 || event.keyCode == 8 || event.keyCode == 46'
The keycodes to 8 and 46 are the delete and backspace. The first solution only works completely in chrome.
It's not a very good style to include js code into html. Also if there is more than one input you need to avoid code duplicating.
So include this to your js file, the other code can be the same
$('.div-with-multiple-inputs').find('input').on('keypress', function() {
return event.charCode >= 48 && event.charCode <= 57;
})
This works for me, allow only numbers 0-9 and .
onkeypress="return event.charCode >= 46 && event.charCode <= 57"

Nyquist criterion - undefined variable in algorithm

I write an algorithm that checks the stability of the closed system of the Nyquist criterion (http://en.wikipedia.org/wiki/Nyquist_stability_criterion)
function answear=stability(re,im)
%% Function check stability of system
%re is real part of transmitation
%im is imagine part of transmitation
%% Check number of vectors elements
re(end +1:5) = 0;
im(end +1:5) = 0;
if( length(re) > length(im))
root = length(re);
else
root = length(im);
end
for w=1:root
tran(w) = re(1) + re(2)*w.^1 + re(3)*w.^2 + re(4)*w.^3 + re(5)*w.^4 +1i*(...
im(1) + im(2)*w.^1 + im(3)*w.^2 + im(4)*w.^3 +im(5)*w.^4);
end
%% Algorithm
switch root
case 0
exist('Write nonzero numbers', 'var')
case 1
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
end
case 2
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
end
end
case 3
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
answear=1;
else
answear=0;
end
end
end
end
case 4
for w=1:length(w)
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
if( real(tran(w)) > 0 && imag(tran(w)) < 0)
answear=1;
else
answear=0;
end
end
end
end
end
end
%% Answear
if answear==1
disp('System unstable')
else
disp('System stable')
end
plot(real(tran),imag(tran))
grid on
end
Function returns
Undefined function or variable "answear".
Error in stability (line 87) if answear==1
So the algorithm is badly written?
Your code could use a lot of cleanup:
Instead of an if-statement such as this one:
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
answear=1;
else
answear=0;
end
you could write a boolean assignment:
answear = real(tran(w)) > 0 & imag(tran(w)) > 0);
Why do you have three (almost) identical nested if-statements at all?
if( real(tran(w)) > 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) > 0)
if( real(tran(w)) < 0 && imag(tran(w)) < 0)
First of all, you could replace everything with one if-statement. But what are you actually testing with this? It seems that those nested if statements are never executed. For instance, real(tran(w)) cannot be both positive and negative at the same time (unless it is a vector you are working on, in which case you shouldn't be using the operator &&).
Also, this is probably your code triggers the error regarding variable answear. Accessing it is impossible since it hasn't been assigned a value (none of the if-statements have been executed).
What is tran, and what is w? Are they global variables? If they are, pass them as input parameters. Your function is probably poorly designed if it relies on external states and variables.
I haven't actually run your code, but these suggestions should make it easier for you to debug it.
P.S:
Please fix the annoying spelling error (it is "answer" and not "answear") :)